OpenBSD FVWM 2.2.5: Modules Rewrite (non-GPL changes) ====================================================== All changes to FVWM modules EXCEPT the GPL code replacement in FvwmRearrange and FvwmBacker/root_bits.c (which are in 0001-gpl-removal.patch). - Added per-module pledge(2) and unveil(2) policies (no two modules share the same policy) 13 modules: pledge stdio 4 modules: pledge stdio rpath 2 modules: pledge stdio rpath wpath cpath + unveil HOME 2 modules: pledge stdio rpath wpath cpath proc exec dns getpw - Removed local allocation wrappers (Mallocs.c/h) from FvwmBacker, FvwmWinList - Removed TRACE_MEMUSE debug tracking from FvwmIconMan - Removed Realloc, alloc_string wrappers from FvwmIconMan - Removed mymalloc debug wrapper from FvwmButtons - Removed static xrealloc from FvwmCpp - Fixed bugs: XQueryTree unchecked (3 files), fopen NULL (FvwmBacker), XGetWindowProperty leak, XSetWMHints(NULL), strcpy overflow, strncat underflow, exit(-1) - Added xpmroot pledge(2) stdio policy - Updated Makefiles (removed Mallocs.c references) - Removed CVS directories from all modules Apply after 0001-gpl-removal.patch and 0002-core-rewrite.patch To apply: cd && patch -p0 < this-file Index: fvwm/modules/FvwmAuto/FvwmAuto.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmAuto/FvwmAuto.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmAuto/FvwmAuto.1 --- fvwm/modules/FvwmAuto/FvwmAuto.1 +++ fvwm/modules/FvwmAuto/FvwmAuto.1 @@ -15,14 +15,14 @@ .if t .sp .5 .. .ta .3i .6i .9i 1.2i 1.5i 1.8i -.TH FvwmAuto 1 "Dec 1, 1994" 2.1 +.TH FVWMAUTO 1 "December 1, 1994" "2.1" "FVWM Modules" .UC .SH NAME \fIFvwmAuto\fP \- the FVWM auto-raise module .SH SYNOPSIS \fIFvwmAuto\fP is spawned by fvwm, so no command line invocation will work. The correct syntax is: -.nf +.PP .EX Module FvwmAuto Timeout [EnterCommand [LeaveCommand]] .sp @@ -32,30 +32,29 @@ AddToMenu Modules "Modules" Title + "Buttons" Module FvwmButtons + "Ident" Module FvwmIdent + "Banner" Module FvwmBanner -+ "Pager" Module FvwmPager 0 3 + "Pager" Module FvwmPager 0 3 .EE -.fi +.PP The \fITimeout\fP argument is required. It specifies how long a window must retain the keyboard input focus before the command is executed. The delay is measured in milliseconds, and any integer 0 or greater is acceptable. - +.PP \fIEnterCommand\fP and \fILeaveCommand\fP are optional. \fIEnterCommand\fP is executed \fITimeout\fP milliseconds after a window gets the input focus, \fILeaveCommand\fP is executed \fITimeout\fP milliseconds after the window has lost focus. - +.PP "Raise" is the default for \fIEnterCommand\fP, but any fvwm2 function is allowed. I would not use "Close" or "Destroy" with a low timeout, though. The \fILeaveCommand\fP can be handy for a tidy desktop. Experiment with: -.nf +.PP .EX Module FvwmAuto 0 Nop Lower Module FvwmAuto 0 Nop Iconify .EE .SH AUTHOR -.nf FvwmAuto just appeared one day, nobody knows how. +.PP FvwmAuto was simply rewritten 09/96, nobody knows by whom. - Index: fvwm/modules/FvwmAuto/FvwmAuto.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmAuto/FvwmAuto.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmAuto/FvwmAuto.c --- fvwm/modules/FvwmAuto/FvwmAuto.c +++ fvwm/modules/FvwmAuto/FvwmAuto.c @@ -22,153 +22,157 @@ #define FALSE #include "config.h" +#include "../fvwm/fvwm_sandbox.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include -#include +#include +#include + #include +#include +#include #include -#include -#include #ifdef HAVE_SYS_SELECT_H #include #endif -#include #include #include +#include + #include "../../fvwm/module.h" #include "../../libs/fvwmlib.h" - /*********************************************************************** * * Procedure: * SIGPIPE handler - SIGPIPE means fvwm is dying * ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(0); + exit(0); } - /*********************************************************************** * * Procedure: * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *enter_fn="Raise", /* default */ - *leave_fn=NULL, - mask_mesg[80]; - unsigned long header[HEADER_SIZE], - *body, - last_win = 0, /* last window handled */ - focus_win = 0; /* current focus */ - int fd_width, - fd[2], - timeout,sec = 0,usec = 0; - struct timeval value, - *delay; - fd_set in_fdset; - - if(argc < 7 || argc > 9) - { - fprintf(stderr,"FvwmAuto can use one to three arguments.\n"); - exit(1); - } - - /* Dead pipes mean fvwm died */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - if ((timeout = atoi(argv[6]))) - { - sec = timeout / 1000; - usec = (timeout % 1000) * 1000; - delay=&value; - } else - delay=NULL; - - if (argv[7]) /* if specified */ - { - if (*argv[7] && !StrEquals(argv[7],"NOP")) /* not empty */ - enter_fn=argv[7]; /* override default */ - else - enter_fn=NULL; /* nop */ - - if (argv[8] && *argv[8] && !StrEquals(argv[8],"NOP")) - /* leave function specified */ - leave_fn=argv[8]; - } + char *enter_fn = "Raise", /* default */ + *leave_fn = NULL, mask_mesg[80]; + unsigned long header[HEADER_SIZE], *body, + last_win = 0, /* last window handled */ + focus_win = 0; /* current focus */ + int fd_width, fd[2], timeout, sec = 0, usec = 0; + struct timeval value, *delay; + fd_set in_fdset; + + if (argc < 7 || argc > 9) { + fprintf(stderr, "FvwmAuto can use one to three arguments.\n"); + exit(1); + } + + /* Dead pipes mean fvwm died */ + signal(SIGPIPE, DeadPipe); + + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + if ((timeout = atoi(argv[6]))) { + sec = timeout / 1000; + usec = (timeout % 1000) * 1000; + delay = &value; + } else + delay = NULL; + + if (argv[7]) { /* if specified */ + if (*argv[7] && !StrEquals(argv[7], "NOP")) /* not empty */ + enter_fn = argv[7]; /* override default */ + else + enter_fn = NULL; /* nop */ + + if (argv[8] && *argv[8] && !StrEquals(argv[8], "NOP")) + /* leave function specified */ + leave_fn = argv[8]; + } #ifdef DEBUG - fprintf(stderr,"[FvwmAuto]: timeout: %d EnterFn: >%s< LeaveFn: >%s<\n",timeout,enter_fn,leave_fn); + fprintf(stderr, "[FvwmAuto]: timeout: %d EnterFn: >%s< LeaveFn: >%s<\n", + timeout, enter_fn, leave_fn); #endif - fd_width = GetFdWidth(); - snprintf(mask_mesg, sizeof(mask_mesg), "SET_MASK %lu\n",(unsigned long)(M_FOCUS_CHANGE)); - SendInfo(fd,mask_mesg,0); + fd_width = GetFdWidth(); + snprintf(mask_mesg, sizeof(mask_mesg), "SET_MASK %lu\n", + (unsigned long)(M_FOCUS_CHANGE)); + SendInfo(fd, mask_mesg, 0); - while(1) - { - FD_ZERO(&in_fdset); - FD_SET(fd[1],&in_fdset); + sandbox_x11_only("FvwmAuto"); - if (delay) /* fill in struct - modified by select() */ - { - delay->tv_sec = sec; - delay->tv_usec = usec; - } - select(fd_width, SELECT_TYPE_ARG234 &in_fdset, 0, 0, - (focus_win == last_win) ? NULL : delay); + while (1) { + FD_ZERO(&in_fdset); + FD_SET(fd[1], &in_fdset); + + if (delay) { /* fill in struct - modified by select() */ + delay->tv_sec = sec; + delay->tv_usec = usec; + } + select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, + (focus_win == last_win) ? NULL : delay); #ifdef DEBUG - fprintf(stderr,"[FvwmAuto]: after select: focus_win: 0x%08lx, last_win: 0x%08lx\n",focus_win, last_win); - fprintf(stderr,"[FvwmAuto]: after select: delay: 0x%08lx, delay struct: %d.%06d sec\n",delay,delay->tv_sec,delay->tv_usec); + fprintf(stderr, + "[FvwmAuto]: after select: focus_win: 0x%08lx, last_win: " + "0x%08lx\n", + focus_win, last_win); + fprintf(stderr, + "[FvwmAuto]: after select: delay: 0x%08lx, delay struct: " + "%d.%06d sec\n", + delay, delay->tv_sec, delay->tv_usec); #endif - if (FD_ISSET(fd[1], &in_fdset) && - ReadFvwmPacket(fd[1],header, &body) > 0) - { - focus_win = body[0]; - free(body); + if (FD_ISSET(fd[1], &in_fdset) && + ReadFvwmPacket(fd[1], header, &body) > 0) { + focus_win = body[0]; + free(body); #ifdef DEBUG - fprintf(stderr,"[FvwmAuto]: M_FOCUS_CHANGE to 0x%08lx\n",focus_win); + fprintf(stderr, + "[FvwmAuto]: M_FOCUS_CHANGE to 0x%08lx\n", + focus_win); #endif - } - if (((FD_ISSET(fd[1], &in_fdset)==0) == (delay!=NULL)) && - /* new message and timeout==0 or */ - /* no message and timeout>0 */ - focus_win!=last_win) /* there's sth. to do */ - { - if (last_win && leave_fn) /* if last_win isn't the root */ - { - SendInfo(fd,leave_fn,last_win); + } + if (((FD_ISSET(fd[1], &in_fdset) == 0) == (delay != NULL)) && + /* new message and timeout==0 or */ + /* no message and timeout>0 */ + focus_win != last_win) { /* there's sth. to do */ + if (last_win && + leave_fn) { /* if last_win isn't the root */ + SendInfo(fd, leave_fn, last_win); #ifdef DEBUG - fprintf(stderr,"[FvwmAuto]: executing %s on window 0x%08lx\n",leave_fn,focus_win); + fprintf(stderr, + "[FvwmAuto]: executing %s on window " + "0x%08lx\n", + leave_fn, focus_win); #endif - } - if (focus_win && enter_fn) /* if focus_win isn't the root */ - { - SendInfo(fd,enter_fn,focus_win); + } + if (focus_win && + enter_fn) { /* if focus_win isn't the root */ + SendInfo(fd, enter_fn, focus_win); #ifdef DEBUG - fprintf(stderr,"[FvwmAuto]: executing %s on window 0x%08lx\n",enter_fn,focus_win); + fprintf(stderr, + "[FvwmAuto]: executing %s on window " + "0x%08lx\n", + enter_fn, focus_win); #endif - } - last_win = focus_win; /* switch to wait mode again */ + } + last_win = focus_win; /* switch to wait mode again */ + } } - } - return 0; + return 0; } - - - Index: fvwm/modules/FvwmBacker/FvwmBacker.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/FvwmBacker.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/FvwmBacker.1 --- fvwm/modules/FvwmBacker/FvwmBacker.1 +++ fvwm/modules/FvwmBacker/FvwmBacker.1 @@ -1,60 +1,51 @@ .\" $OpenBSD: FvwmBacker.1,v 1.1.1.1 2006/11/26 10:53:43 matthieu Exp $ .\" t .\" @(#)FvwmBacker.1 11/8/94 -.TH FvwmBacker 1 "September 8th, 1994" 0.1 +.TH FVWMBACKER 1 "September 8, 1994" "0.1" "FVWM Modules" .UC .SH NAME FvwmBacker \- the FVWM background changer module .SH SYNOPSIS FvwmBacker is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION - The FvwmBacker module provides functionality to change the background when changing desktops. Any command can be executed to change the backgrounds. Actually, any arbitrary command can be sent to fvwm to execute, so you could also do things such as changing window border colors, etc. - .SH COPYRIGHTS The FvwmBacker module is the original work of Mike Finger. - -Copyright 1994, Mike Finger. The author makes no guarantees or -warranties of any kind about the use of this module. Use this modules +.PP +Copyright 1994, Mike Finger. The author makes no guarantees or +warranties of any kind about the use of this module. Use this module at your own risk. You may freely use this module or any portion of it for any purpose as long as the copyright is kept intact. - .SH INITIALIZATION During initialization, \fIFvwmBacker\fP will scan the same configuration file that FVWM used during startup to find the options that pertain to it. These options are discussed in a later section. - .SH INVOCATION FvwmBacker can be invoked by fvwm during initialization by inserting the line 'Module FvwmBacker' in the .fvwmrc file. - +.PP FvwmBacker must reside in a directory that is listed in the ModulePath option of FVWM for it to be executed by FVWM. - .SH CONFIGURATION OPTIONS The following is the only supported option at present: - .IP "*FvwmBackerDesk \fIDeskNumber command\fP" Specifies the \fIcommand\fP to execute when the specified \fIDeskNumber\fP becomes active. - +.PP If the command begins with \fI-solid\fP FvwmBacker uses the next argument as a color in the X database and sets the background to that color without generating a system call to xsetroot (only single word color names may be used). Otherwise the command is sent to fvwm to execute. - .SH SAMPLE CONFIGURATION The following are excepts from an .fvwmrc file which describe FvwmBacker initialization commands: - -.nf -.sp +.PP +.EX #### # Set Up Backgrounds for different desktops. #### @@ -62,12 +53,10 @@ FvwmBacker initialization commands: *FvwmBackerDesk 1 -solid midnightblue *FvwmBackerDesk 2 -solid yellow *FvwmBackerDesk 3 Exec xpmroot /usr/include/X11/pixmaps/background2.xpm -.sp -.fi - +.EE .SH AUTHOR Mike Finger (mfinger@mermaid.micro.umn.edu) - (Mike_Finger@atk.com) - (doodman on IRC, check the #linux channel) -.SH Modified by +.PP +(Mike_Finger@atk.com) +.SH MODIFIED BY Andrew Davison (davison@cs.monash.edu.au) Index: fvwm/modules/FvwmBacker/FvwmBacker.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/FvwmBacker.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/FvwmBacker.c --- fvwm/modules/FvwmBacker/FvwmBacker.c +++ fvwm/modules/FvwmBacker/FvwmBacker.c @@ -25,48 +25,45 @@ * A. Davison * Septmber 1994. */ -#include "config.h" +#include +#include -#include -#include #include +#include +#include #include -#include -#include + +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" #ifdef HAVE_SYS_SELECT_H #include #endif -#include #include +#include -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ -#endif /* Saul */ +#endif /* Saul */ +#include #include #include "../../fvwm/module.h" #include "FvwmBacker.h" -#include "Mallocs.h" - -#include unsigned long GetColor(char *color); -typedef struct -{ - int type; /* The command type. - * -1 = no command. - * 0 = command to be spawned - * 1 = a solid color to be set */ - char* cmdStr; /* The command string (Type 0) */ - unsigned long solidColor; /* A solid color after X parsing (Type 1) */ +typedef struct { + int type; /* The command type. + * -1 = no command. + * 0 = command to be spawned + * 1 = a solid color to be set */ + char *cmdStr; /* The command string (Type 0) */ + unsigned long solidColor; /* A solid color after X parsing (Type 1) */ } Command; Command *commands; -int DeskCount=0; +int DeskCount = 0; int Fvwm_fd[2]; int fd_width; @@ -75,104 +72,110 @@ char *Module; /* X Display information. */ -Display* dpy; -Window root; -int screen; +Display *dpy; +Window root; +int screen; -FILE* logFile; +FILE *logFile; /* Comment this out if you don't want a logfile. */ /* #define LOGFILE "/tmp/FvwmBacker.log"*/ - -int main(int argc, char **argv) +int +main(int argc, char **argv) { -char *temp, *s; - char* displayName = NULL; + char *temp, *s; + char *displayName = NULL; - commands=NULL; + commands = NULL; - /* Save the program name for error messages and config parsing */ - temp = argv[0]; - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; + /* Save the program name for error messages and config parsing */ + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; - Module=temp; + Module = temp; - if((argc != 6)&&(argc != 7)) { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module, - VERSION); - exit(1); - } + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", Module, + VERSION); + exit(1); + } - Fvwm_fd[0] = atoi(argv[1]); - Fvwm_fd[1] = atoi(argv[2]); + Fvwm_fd[0] = atoi(argv[1]); + Fvwm_fd[1] = atoi(argv[2]); - /* Grab the X display information now. */ + /* Grab the X display information now. */ dpy = XOpenDisplay(displayName); - if (!dpy) - { - fprintf(stderr, "%s: unable to open display '%s'\n", - Module, XDisplayName (displayName)); - exit (2); + if (!dpy) { + fprintf(stderr, "%s: unable to open display '%s'\n", Module, + XDisplayName(displayName)); + exit(2); } screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); /* Open a log file if necessary */ -# ifdef LOGFILE - logFile = fopen(LOGFILE,"a"); - fprintf(logFile,"Initialising FvwmBacker\n"); -# endif - - signal (SIGPIPE, DeadPipe); +#ifdef LOGFILE + logFile = fopen(LOGFILE, "a"); + if (logFile != NULL) + fprintf(logFile, "Initialising FvwmBacker\n"); +#endif - /* Parse the config file */ - ParseConfig(); + signal(SIGPIPE, DeadPipe); - fd_width = GetFdWidth(); + /* Parse the config file */ + ParseConfig(); - SetMessageMask(Fvwm_fd,M_NEW_DESK|M_CONFIG_INFO|M_END_CONFIG_INFO); + fd_width = GetFdWidth(); - /* - ** we really only want the current desk, and window list sends it - */ - SendInfo(Fvwm_fd,"Send_WindowList",0); + SetMessageMask(Fvwm_fd, M_NEW_DESK | M_CONFIG_INFO | M_END_CONFIG_INFO); + /* + ** we really only want the current desk, and window list sends it + */ + SendInfo(Fvwm_fd, "Send_WindowList", 0); - /* Recieve all messages from Fvwm */ - EndLessLoop(); + /* Recieve all messages from Fvwm */ + EndLessLoop(); - /* Should never get here! */ - return 1; + /* Should never get here! */ + return 1; } /****************************************************************************** EndLessLoop - Read until we get killed, blocking when can't read ******************************************************************************/ -void EndLessLoop() +void +EndLessLoop() { -fd_set readset; -struct timeval tv; - - while(1) { - FD_ZERO(&readset); - FD_SET(Fvwm_fd[1],&readset); - tv.tv_sec=0; - tv.tv_usec=0; - - if (!select(fd_width,SELECT_TYPE_ARG234 &readset,NULL,NULL,&tv)) { - FD_ZERO(&readset); - FD_SET(Fvwm_fd[1],&readset); - select(fd_width,SELECT_TYPE_ARG234 &readset,NULL,NULL,NULL); - } - - if (!FD_ISSET(Fvwm_fd[1],&readset)) continue; - ReadFvwmPipe(); - } + fd_set readset; + struct timeval tv; + + sandbox_x11_only("FvwmBacker"); + + while (1) { + FD_ZERO(&readset); + FD_SET(Fvwm_fd[1], &readset); + tv.tv_sec = 0; + tv.tv_usec = 0; + + if (!select(fd_width, SELECT_TYPE_ARG234 & readset, NULL, NULL, + &tv)) { + FD_ZERO(&readset); + FD_SET(Fvwm_fd[1], &readset); + select(fd_width, SELECT_TYPE_ARG234 & readset, NULL, + NULL, NULL); + } + + if (!FD_ISSET(Fvwm_fd[1], &readset)) + continue; + ReadFvwmPipe(); + } } /****************************************************************************** @@ -180,75 +183,69 @@ struct timeval tv; Originally Loop() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ReadFvwmPipe() +void +ReadFvwmPipe() { - int count; - unsigned long header[HEADER_SIZE],*body; - - body = NULL; - if((count = ReadFvwmPacket(Fvwm_fd[1],header,&body)) > 0) - { - ProcessMessage(header[1],body); - free(body); - } -} + int count; + unsigned long header[HEADER_SIZE], *body; + body = NULL; + if ((count = ReadFvwmPacket(Fvwm_fd[1], header, &body)) > 0) { + ProcessMessage(header[1], body); + free(body); + } +} /****************************************************************************** ProcessMessage - Process the message coming from Fvwm Skeleton based on processmessage() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ProcessMessage(unsigned long type,unsigned long *body) +void +ProcessMessage(unsigned long type, unsigned long *body) { - if (type==M_NEW_DESK) - { - if (body[0]>DeskCount || commands[body[0]].type == -1) - { - return; - } + if (type == M_NEW_DESK) { + if (body[0] > DeskCount || commands[body[0]].type == -1) { + return; + } #ifdef LOGFILE - fprintf(logFile,"Desk: %d\n",body[0]); - fprintf(logFile,"Command type: %d\n",commands[body[0]].type); - if (commands[body[0]].type == 0) - fprintf(logFile,"Command String: %s\n",commands[body[0]].cmdStr); - else if (commands[body[0]].type == 1) - fprintf(logFile,"Color Number: %d\n",commands[body[0]].solidColor); - else if (commands[body[0]].type == -1) - fprintf(logFile,"No Command\n"); - else - { - fprintf(logFile,"Illegal command type !\n"); - exit(1); - } - fflush(logFile); -# endif - + fprintf(logFile, "Desk: %d\n", body[0]); + fprintf(logFile, "Command type: %d\n", commands[body[0]].type); + if (commands[body[0]].type == 0) + fprintf(logFile, "Command String: %s\n", + commands[body[0]].cmdStr); + else if (commands[body[0]].type == 1) + fprintf(logFile, "Color Number: %d\n", + commands[body[0]].solidColor); + else if (commands[body[0]].type == -1) + fprintf(logFile, "No Command\n"); + else { + fprintf(logFile, "Illegal command type !\n"); + exit(1); + } + fflush(logFile); +#endif - if (commands[body[0]].type == 1) - { - /* Process a solid color request */ + if (commands[body[0]].type == 1) { + /* Process a solid color request */ - XSetWindowBackground(dpy, root, commands[body[0]].solidColor); - XClearWindow(dpy, root); - XFlush(dpy); - /* XSetWindowBackground(dpy, root, commands[body[0]].solidColor); - */ + XSetWindowBackground( + dpy, root, commands[body[0]].solidColor); + XClearWindow(dpy, root); + XFlush(dpy); + /* XSetWindowBackground(dpy, root, + * commands[body[0]].solidColor); + */ -# ifdef LOGFILE - fprintf(logFile,"Color set.\n"); - fflush(logFile); -# endif - } - else if(commands[body[0]].cmdStr != NULL) - { -#if 0 - system(commands[body[0]].cmdStr); -#else /* much more useful: */ - SendFvwmPipe(commands[body[0]].cmdStr, (unsigned long)0); +#ifdef LOGFILE + fprintf(logFile, "Color set.\n"); + fflush(logFile); #endif + } else if (commands[body[0]].cmdStr != NULL) { + SendFvwmPipe( + commands[body[0]].cmdStr, (unsigned long)0); + } } - } } /****************************************************************************** @@ -256,34 +253,38 @@ void ProcessMessage(unsigned long type,unsigned long *body) Based on SendInfo() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void SendFvwmPipe(char *message,unsigned long window) +void +SendFvwmPipe(char *message, unsigned long window) { -int w; -char *hold,*temp,*temp_msg; - hold=message; - - while(1) { - temp=strchr(hold,','); - if (temp!=NULL) { - temp_msg=malloc(temp-hold+1); - strncpy(temp_msg,hold,(temp-hold)); - temp_msg[(temp-hold)]='\0'; - hold=temp+1; - } else temp_msg=hold; - - write(Fvwm_fd[0],&window, sizeof(unsigned long)); - - w=strlen(temp_msg); - write(Fvwm_fd[0],&w,sizeof(int)); - write(Fvwm_fd[0],temp_msg,w); - - /* keep going */ - w=1; - write(Fvwm_fd[0],&w,sizeof(int)); - - if(temp_msg!=hold) free(temp_msg); - else break; - } + int w; + char *hold, *temp, *temp_msg; + hold = message; + + while (1) { + temp = strchr(hold, ','); + if (temp != NULL) { + temp_msg = malloc(temp - hold + 1); + strncpy(temp_msg, hold, (temp - hold)); + temp_msg[(temp - hold)] = '\0'; + hold = temp + 1; + } else + temp_msg = hold; + + write(Fvwm_fd[0], &window, sizeof(unsigned long)); + + w = strlen(temp_msg); + write(Fvwm_fd[0], &w, sizeof(int)); + write(Fvwm_fd[0], temp_msg, w); + + /* keep going */ + w = 1; + write(Fvwm_fd[0], &w, sizeof(int)); + + if (temp_msg != hold) + free(temp_msg); + else + break; + } } /*********************************************************************** @@ -291,9 +292,10 @@ char *hold,*temp,*temp_msg; Based on DeadPipe() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. **********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(1); + exit(1); } /****************************************************************************** @@ -301,86 +303,83 @@ void DeadPipe(int nonsense) Based on part of main() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ParseConfig() +void +ParseConfig() { - char line2[40]; - char *tline; - - sprintf(line2,"*%sDesk",Module); - - GetConfigLine(Fvwm_fd,&tline); - - while(tline != (char *)0) - { - if(strlen(tline)>1) - { - if(strncasecmp(tline,line2,strlen(line2))==0) - AddCommand(&tline[strlen(line2)]); - } - GetConfigLine(Fvwm_fd,&tline); - } + char line2[40]; + char *tline; + + snprintf(line2, sizeof(line2), "*%sDesk", Module); + + GetConfigLine(Fvwm_fd, &tline); + + while (tline != (char *)0) { + if (strlen(tline) > 1) { + if (strncasecmp(tline, line2, strlen(line2)) == 0) + AddCommand(&tline[strlen(line2)]); + } + GetConfigLine(Fvwm_fd, &tline); + } } /****************************************************************************** AddCommand - Add a command to the correct spot on the dynamic array. ******************************************************************************/ -void AddCommand(char *string) +void +AddCommand(char *string) { -char *temp; -int num; - temp=string; - while(isspace(*temp)) temp++; - num=atoi(temp); - while(!isspace(*temp)) temp++; - while(isspace(*temp)) temp++; - if (DeskCount<1) { - commands=(Command*)safemalloc((num+1)*sizeof(Command)); - while(DeskCountDeskCount) { - commands=(Command*)realloc(commands,(num+1)*sizeof(Command)); - while(DeskCount DeskCount) { + commands = (Command *)xrealloc( + (char *)commands, (num + 1) * sizeof(Command)); + while (DeskCount < num + 1) + commands[DeskCount++].type = -1; + } + } + + if (strncmp(temp, "-solid", 6) == 0) { + char *color; + char *tmp; /* Process a solid color request */ color = &temp[7]; while (isspace(*color)) color++; - tmp= color; + tmp = color; while (!isspace(*tmp)) tmp++; *tmp = 0; commands[num].type = 1; commands[num].solidColor = (!color || !*color) ? - BlackPixel(dpy, screen) : - GetColor(color); + BlackPixel(dpy, screen) : + GetColor(color); #ifdef LOGFILE - fprintf(logFile,"Adding color: %s as number %d to desk %d\n", - color,commands[num].solidColor, num); + fprintf(logFile, "Adding color: %s as number %d to desk %d\n", + color, commands[num].solidColor, num); fflush(logFile); #endif - } - else - { + } else { #ifdef LOGFILE - fprintf(logFile,"Adding command: %s to desk %d\n",temp, num); + fprintf(logFile, "Adding command: %s to desk %d\n", temp, num); fflush(logFile); #endif commands[num].type = 0; - commands[num].cmdStr = (char *)safemalloc(strlen(temp)+1); - strcpy(commands[num].cmdStr,temp); + size_t cmd_len = strlen(temp); + commands[num].cmdStr = (char *)xmalloc(cmd_len + 1); + strlcpy(commands[num].cmdStr, temp, cmd_len + 1); } - } Index: fvwm/modules/FvwmBacker/FvwmBacker.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/FvwmBacker.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/FvwmBacker.h --- fvwm/modules/FvwmBacker/FvwmBacker.h +++ fvwm/modules/FvwmBacker/FvwmBacker.h @@ -1,4 +1,4 @@ -/* FvwmBacker Module for Fvwm. +/* FvwmBacker Module for Fvwm. * * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or * Mike_Finger@atk.com) @@ -18,14 +18,14 @@ * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ -#include "../../libs/fvwmlib.h" +#include "../../libs/fvwmlib.h" /* Function Prototypes */ void EndLessLoop(); void ReadFvwmPipe(); -void ProcessMessage(unsigned long type,unsigned long *body); -void SendFvwmPipe(char *message,unsigned long window); +void ProcessMessage(unsigned long type, unsigned long *body); +void SendFvwmPipe(char *message, unsigned long window); void DeadPipe(int nonsense); void ParseConfig(void); void AddCommand(char *string); Index: fvwm/modules/FvwmBacker/Makefile =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/Makefile,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/Makefile --- fvwm/modules/FvwmBacker/Makefile +++ fvwm/modules/FvwmBacker/Makefile @@ -5,7 +5,7 @@ .PATH: ${DIST}/modules/FvwmBacker PROG= FvwmBacker -SRCS= FvwmBacker.c Mallocs.c root_bits.c +SRCS= FvwmBacker.c root_bits.c LDADD+= -lXpm ${XLIB} BINDIR= ${FVWMLIBDIR} Index: fvwm/modules/FvwmBacker/Mallocs.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/Mallocs.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/Mallocs.c --- fvwm/modules/FvwmBacker/Mallocs.c +++ /dev/null @@ -1,55 +0,0 @@ -/* FvwmWinList Module for Fvwm. - * - * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or - * Mike_Finger@atk.com) - * - * The author makes not guarantees or warantees, either express or - * implied. Feel free to use any contained here for any purpose, as long - * and this and any other applicible copyrights are kept intact. - - * The functions in this source file that are based on part of the FvwmIdent - * module for Fvwm are noted by a small copyright atop that function, all others - * are copyrighted by Mike Finger. For those functions modified/used, here is - * the full, original copyright: - * - * Copyright 1994, Robert Nation and Nobutaka Suzuki. - * No guarantees or warantees or anything - * are provided or implied in any way whatsoever. Use this program at your - * own risk. Permission to use this program for any purpose is given, - * as long as the copyright is kept intact. */ - -#include "config.h" -#include -#include -#include -#include -#include -#include "../../libs/fvwmlib.h" - -extern char *Module; - -/****************************************************************************** - saferealloc - safely reallocate memory or exit if fails. (Doesn't work right) -******************************************************************************/ -char *saferealloc(char *ptr, int length) -{ -char *newptr; - - if(length <=0) length=1; - - newptr=realloc(ptr,length); - if (ptr == (char *)0) { - fprintf(stderr,"%s:realloc failed",Module); - exit(1); - } - return ptr; -} - -void UpdateString(char **string,char *value) -{ - if (value==NULL) return; - if (*string==NULL) *string=safemalloc(strlen(value)+1); - else *string=(char *)realloc(*string,strlen(value)+1); - strcpy(*string,value); -} - Index: fvwm/modules/FvwmBacker/Mallocs.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/Mallocs.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/Mallocs.h --- fvwm/modules/FvwmBacker/Mallocs.h +++ /dev/null @@ -1,24 +0,0 @@ -/* FvwmBacker Module for Fvwm. - * - * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or - * Mike_Finger@atk.com) - * - * The author makes not guarantees or warantees, either express or - * implied. Feel free to use any contained here for any purpose, as long - * and this and any other applicible copyrights are kept intact. - - * The functions in this source file that are based on part of the FvwmIdent - * module for Fvwm are noted by a small copyright atop that function, all others - * are copyrighted by Mike Finger. For those functions modified/used, here is - * the full, original copyright: - * - * Copyright 1994, Robert Nation and Nobutaka Suzuki. - * No guarantees or warantees or anything - * are provided or implied in any way whatsoever. Use this program at your - * own risk. Permission to use this program for any purpose is given, - * as long as the copyright is kept intact. */ - -/* Function Prototypes */ -char *safemalloc(int length); -char *saferealloc(char *ptr, int length); -void UpdateString(char **string,char *value); Index: fvwm/modules/FvwmBanner/FvwmBanner.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBanner/FvwmBanner.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBanner/FvwmBanner.1 --- fvwm/modules/FvwmBanner/FvwmBanner.1 +++ fvwm/modules/FvwmBanner/FvwmBanner.1 @@ -1,41 +1,33 @@ .\" $OpenBSD: FvwmBanner.1,v 1.1.1.1 2006/11/26 10:53:43 matthieu Exp $ .\" t .\" @(#)FvwmBanner.1 1/12/94 -.TH FvwmBanner 1 "Jan 28, 1994" 1.20 +.TH FVWMBANNER 1 "January 28, 1994" "1.20" "FVWM Modules" .UC .SH NAME FvwmBanner \- the FVWM Banner .SH SYNOPSIS FvwmBanner is intended to be spawned by fvwm. - .SH DESCRIPTION -The FvwmInitBanner displays an Fvwm Logo in the center of the screen -for 3 seconds. - +The FvwmInitBanner displays an Fvwm Logo in the center of the screen for 3 +seconds. .SH COPYRIGHTS None. - .SH INITIALIZATION Nothing interesting. - .SH INVOCATION -FvwmBanner can be invoked by binding the action 'Module FvwmBanner' to -a menu or key-stroke in the .fvwmrc file. Fvwm will search directory +FvwmBanner can be invoked by binding the action 'Module FvwmBanner' to a +menu or key-stroke in the .fvwmrc file. Fvwm will search the directory specified in the ModulePath configuration option to attempt to locate -FvwmBanner. Although nothing keeps you from launching FvwmBanner at -start-up time, you probably don't want to. You can also give it an -optional file parameter, like 'FvwmBanner doomface.xpm' or spcify an -alternate default pixmap via configuration options. - +FvwmBanner. Although nothing keeps you from launching FvwmBanner at +start-up time, you probably do not want to. +.PP +You can also give it an optional file parameter, for example +\fBFvwmBanner doomface.xpm\fP, +or specify an alternate default pixmap via configuration options. .SH CONFIGURATION OPTIONS - .IP "*FvwmBannerPixmap \fIfile\fP" Tells the module to display \fIfile\fP instead of the built in pixmap. - .IP "*FvwmBannerTimeout \fIsec\fP" Tells the module to display for \fIsec\fP seconds instead of default of 3. - - .SH AUTHOR -Robert Nation - +Robert Nation Index: fvwm/modules/FvwmBanner/FvwmBanner.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBanner/FvwmBanner.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBanner/FvwmBanner.c --- fvwm/modules/FvwmBanner/FvwmBanner.c +++ fvwm/modules/FvwmBanner/FvwmBanner.c @@ -6,56 +6,48 @@ ***************************************************************************/ #include "config.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ +#include "../../fvwm/fvwm_sandbox.h" #endif -#include -#include +#include +#include + #include +#include +#include #include -#include -#include #ifdef HAVE_SYS_SELECT_H #include #endif -#include -#include -#include - -#include #include #include +#include #include - #include - - -#include "../../libs/fvwmlib.h" +#include +#include +#include #include "../../icons/fvwm2_big.xpm" -#if 0 -#include "../../icons/k2.xpm" -#endif /* 0 */ - +#include "../../libs/fvwmlib.h" typedef struct _XpmIcon { - Pixmap pixmap; - Pixmap mask; - XpmAttributes attributes; -} XpmIcon; + Pixmap pixmap; + Pixmap mask; + XpmAttributes attributes; +} XpmIcon; /************************************************************************** * A few function prototypes **************************************************************************/ void RedrawWindow(void); void GetXPMData(char **); -void GetXPMFile(char *,char *); +void GetXPMFile(char *, char *); void change_window_name(char *str); -int flush_expose (Window w); -static void parseOptions (int fd[2]); +int flush_expose(Window w); +static void parseOptions(int fd[2]); XpmIcon view; Window win; @@ -66,7 +58,7 @@ char *myName = NULL; int timeout = 3000000; /* default time of 3 seconds */ -Display *dpy; /* which display are we talking to */ +Display *dpy; /* which display are we talking to */ Window Root; int screen; int x_fd; @@ -74,176 +66,160 @@ int d_depth; int ScreenWidth, ScreenHeight; XSizeHints mysizehints; Pixel back_pix, fore_pix; -GC NormalGC,FGC; +GC NormalGC, FGC; static Atom wm_del_win; Colormap colormap; -#define MW_EVENTS (ExposureMask | ButtonReleaseMask) +#define MW_EVENTS (ExposureMask | ButtonReleaseMask) /**************************************************************************** * * Creates an icon window as needed * ****************************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *display_name = NULL, *string = NULL; - int retval = 0; - XEvent Event; - fd_set in_fdset; - int fd_width ; - struct timeval value; - int fd[2]; - - fd_width = GetFdWidth(); - - /* Save our program name - for error messages */ - string = strrchr (argv[0], '/'); - if (string != (char *) 0) string++; - - myName = safemalloc (strlen (string) + 1); - strcpy (myName, string); - - if(argc>=3) - { - /* sever our connection with fvwm, if we have one. */ - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - -#if 0 - if(fd[0]>0)close(fd[0]); - if(fd[1]>0)close(fd[1]); -#endif /* 0 */ - } - else - { - fprintf (stderr, - "%s version %s should only be executed by fvwm!\n", - myName, - VERSION); - exit(1); - } - - if (argc > 6) { - pixmapName = safemalloc (strlen (argv[6]) + 1); - strcpy (pixmapName, argv[6]); - } - - /* Open the display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"FvwmBanner: can't open display %s", - XDisplayName(display_name)); - exit (1); - } - screen= DefaultScreen(dpy); - Root = RootWindow(dpy, screen); - colormap = XDefaultColormap(dpy,screen); - d_depth = DefaultDepth(dpy, screen); - x_fd = XConnectionNumber(dpy); - - ScreenHeight = DisplayHeight(dpy,screen); - ScreenWidth = DisplayWidth(dpy,screen); - - parseOptions(fd); - - /* Get the xpm banner */ - if (pixmapName) - GetXPMFile(pixmapName,pixmapPath); - else -#if 0 - if(d_depth > 4) - GetXPMData(k2_xpm); - else -#endif /* 0 */ - GetXPMData(fvwm2_big_xpm); - - /* Create a window to hold the banner */ - mysizehints.flags= - USSize|USPosition|PWinGravity|PResizeInc|PBaseSize|PMinSize|PMaxSize; - /* subtract one for the right/bottom border */ - mysizehints.width = view.attributes.width; - mysizehints.height=view.attributes.height; - mysizehints.width_inc = 1; - mysizehints.height_inc = 1; - mysizehints.base_height = mysizehints.height; - mysizehints.base_width = mysizehints.width; - mysizehints.min_height = mysizehints.height; - mysizehints.min_width = mysizehints.width; - mysizehints.max_height = mysizehints.height; - mysizehints.max_width = mysizehints.width; - mysizehints.win_gravity = NorthWestGravity; - - mysizehints.x = (ScreenWidth - view.attributes.width)/2; - mysizehints.y = (ScreenHeight - view.attributes.height)/2; - - win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y, - mysizehints.width,mysizehints.height, - 0,fore_pix ,None); - - - /* Set assorted info for the window */ - XSetTransientForHint(dpy,win,Root); - wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); - XSetWMProtocols(dpy,win,&wm_del_win,1); - - XSetWMNormalHints(dpy,win,&mysizehints); - change_window_name("FvwmBanner"); - - XSetWindowBackgroundPixmap(dpy,win,view.pixmap); + char *display_name = NULL, *string = NULL; + int retval = 0; + XEvent Event; + fd_set in_fdset; + int fd_width; + struct timeval value; + int fd[2]; + + fd_width = GetFdWidth(); + + /* Save our program name - for error messages */ + string = strrchr(argv[0], '/'); + if (string != (char *)0) + string++; + else + string = argv[0]; + + size_t name_len = strlen(string); + myName = xmalloc(name_len + 1); + strlcpy(myName, string, name_len + 1); + + if (argc >= 3) { + /* sever our connection with fvwm, if we have one. */ + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + } else { + fprintf(stderr, + "%s version %s should only be executed by fvwm!\n", myName, + VERSION); + exit(1); + } + + if (argc > 6) { + size_t pixmap_len = strlen(argv[6]); + pixmapName = xmalloc(pixmap_len + 1); + strlcpy(pixmapName, argv[6], pixmap_len + 1); + } + + /* Open the display */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "FvwmBanner: can't open display %s", + XDisplayName(display_name)); + exit(1); + } + screen = DefaultScreen(dpy); + Root = RootWindow(dpy, screen); + colormap = XDefaultColormap(dpy, screen); + d_depth = DefaultDepth(dpy, screen); + x_fd = XConnectionNumber(dpy); + + ScreenHeight = DisplayHeight(dpy, screen); + ScreenWidth = DisplayWidth(dpy, screen); + + parseOptions(fd); + + /* Get the xpm banner */ + if (pixmapName) + GetXPMFile(pixmapName, pixmapPath); + else + GetXPMData(fvwm2_big_xpm); + + /* Create a window to hold the banner */ + mysizehints.flags = USSize | USPosition | PWinGravity | PResizeInc | + PBaseSize | PMinSize | PMaxSize; + /* subtract one for the right/bottom border */ + mysizehints.width = view.attributes.width; + mysizehints.height = view.attributes.height; + mysizehints.width_inc = 1; + mysizehints.height_inc = 1; + mysizehints.base_height = mysizehints.height; + mysizehints.base_width = mysizehints.width; + mysizehints.min_height = mysizehints.height; + mysizehints.min_width = mysizehints.width; + mysizehints.max_height = mysizehints.height; + mysizehints.max_width = mysizehints.width; + mysizehints.win_gravity = NorthWestGravity; + + mysizehints.x = (ScreenWidth - view.attributes.width) / 2; + mysizehints.y = (ScreenHeight - view.attributes.height) / 2; + + win = XCreateSimpleWindow(dpy, Root, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, 0, fore_pix, None); + + /* Set assorted info for the window */ + XSetTransientForHint(dpy, win, Root); + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + XSetWMProtocols(dpy, win, &wm_del_win, 1); + + XSetWMNormalHints(dpy, win, &mysizehints); + change_window_name("FvwmBanner"); + + XSetWindowBackgroundPixmap(dpy, win, view.pixmap); #ifdef SHAPE - if(view.mask != None) - XShapeCombineMask(dpy, win, ShapeBounding,0,0,view.mask, ShapeSet); + if (view.mask != None) + XShapeCombineMask( + dpy, win, ShapeBounding, 0, 0, view.mask, ShapeSet); #endif - XMapWindow(dpy,win); - XSync(dpy,0); -#if 0 - usleep(timeout); -#else - XSelectInput(dpy,win,ButtonReleaseMask); - /* Display the window */ - value.tv_usec = timeout % 1000000; - value.tv_sec = timeout / 1000000; - while(1) - { - FD_ZERO(&in_fdset); - FD_SET(x_fd,&in_fdset); - - if(!XPending(dpy)) - - retval=select(fd_width,SELECT_TYPE_ARG234 &in_fdset, 0, 0, &value); - - if (retval==0) - { - XDestroyWindow(dpy,win); - XSync(dpy,0); - exit(0); - } - - if(FD_ISSET(x_fd, &in_fdset)) - { - /* read a packet */ - XNextEvent(dpy,&Event); - switch(Event.type) - { - case ButtonRelease: - XDestroyWindow(dpy,win); - XSync(dpy,0); - exit(0); - case ClientMessage: - if (Event.xclient.format==32 && Event.xclient.data.l[0]==wm_del_win) - { - XDestroyWindow(dpy,win); - XSync(dpy,0); - exit(0); - } - default: - break; - } - } - } -#endif /* 0 */ - return 0; + XMapWindow(dpy, win); + XSync(dpy, 0); + XSelectInput(dpy, win, ButtonReleaseMask); + /* Display the window */ + value.tv_usec = timeout % 1000000; + value.tv_sec = timeout / 1000000; + sandbox_x11_only("FvwmBanner"); + + while (1) { + FD_ZERO(&in_fdset); + FD_SET(x_fd, &in_fdset); + + if (!XPending(dpy)) + retval = select(fd_width, SELECT_TYPE_ARG234 & in_fdset, + 0, 0, &value); + + if (retval == 0) { + XDestroyWindow(dpy, win); + XSync(dpy, 0); + exit(0); + } + + if (FD_ISSET(x_fd, &in_fdset)) { + /* read a packet */ + XNextEvent(dpy, &Event); + switch (Event.type) { + case ButtonRelease: + XDestroyWindow(dpy, win); + XSync(dpy, 0); + exit(0); + case ClientMessage: + if (Event.xclient.format == 32 && + Event.xclient.data.l[0] == wm_del_win) { + XDestroyWindow(dpy, win); + XSync(dpy, 0); + exit(0); + } + default: + break; + } + } + } + return 0; } /**************************************************************************** @@ -251,116 +227,108 @@ int main(int argc, char **argv) * Looks for a color XPM icon file * ****************************************************************************/ -void GetXPMData(char **data) +void +GetXPMData(char **data) { - view.attributes.valuemask = XpmReturnPixels| XpmCloseness | XpmExtensions; - view.attributes.closeness = 40000 /* Allow for "similar" colors */; - if(XpmCreatePixmapFromData(dpy, Root, data, - &view.pixmap, &view.mask, - &view.attributes)!=XpmSuccess) - { - fprintf(stderr,"FvwmBanner: ERROR couldn't convert data to pixmap\n"); - exit(1); - } + view.attributes.valuemask = + XpmReturnPixels | XpmCloseness | XpmExtensions; + view.attributes.closeness = 40000 /* Allow for "similar" colors */; + if (XpmCreatePixmapFromData(dpy, Root, data, &view.pixmap, &view.mask, + &view.attributes) != XpmSuccess) { + fprintf(stderr, + "FvwmBanner: ERROR couldn't convert data to pixmap\n"); + exit(1); + } } -void GetXPMFile(char *file, char *path) + +void +GetXPMFile(char *file, char *path) { - char *full_file = NULL; - - view.attributes.valuemask = XpmReturnPixels| XpmCloseness | XpmExtensions; - view.attributes.closeness = 40000 /* Allow for "similar" colors */; - - if (file) - full_file = findIconFile(file,path,R_OK); - - if (full_file) - { - if(XpmReadFileToPixmap(dpy, - Root, - full_file, - &view.pixmap, - &view.mask, - &view.attributes) == XpmSuccess) - { - return; - } - fprintf(stderr,"FvwmBanner: ERROR reading pixmap file\n"); - } - else - fprintf(stderr,"FvwmBanner: ERROR finding pixmap file in PixmapPath\n"); - GetXPMData(fvwm2_big_xpm); + char *full_file = NULL; + + view.attributes.valuemask = + XpmReturnPixels | XpmCloseness | XpmExtensions; + view.attributes.closeness = 40000 /* Allow for "similar" colors */; + + if (file) + full_file = findIconFile(file, path, R_OK); + + if (full_file) { + if (XpmReadFileToPixmap(dpy, Root, full_file, &view.pixmap, + &view.mask, &view.attributes) == XpmSuccess) { + return; + } + fprintf(stderr, "FvwmBanner: ERROR reading pixmap file\n"); + } else + fprintf(stderr, + "FvwmBanner: ERROR finding pixmap file in PixmapPath\n"); + GetXPMData(fvwm2_big_xpm); } -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"FvwmBanner: can't %s %s\n", a,b); + fprintf(stderr, "FvwmBanner: can't %s %s\n", a, b); } -static void parseOptions (int fd[2]) +static void +parseOptions(int fd[2]) { - char *tline= NULL; - int clength; - - clength = strlen (myName); - - while (GetConfigLine (fd, &tline),tline != NULL) - { - if (strlen (tline) > 1) - { - if (strncasecmp (tline, - CatString3 ("*", myName, "Pixmap"), - clength + 7) ==0) - { - if (pixmapName == (char *) 0) - { - CopyString (&pixmapName, &tline[clength+7]); - if (pixmapName[0] == 0) - { - free (pixmapName); - pixmapName = (char *) 0; - } + char *tline = NULL; + int clength; + + clength = strlen(myName); + + while (GetConfigLine(fd, &tline), tline != NULL) { + if (strlen(tline) > 1) { + if (strncasecmp(tline, + CatString3("*", myName, "Pixmap"), + clength + 7) == 0) { + if (pixmapName == (char *)0) { + CopyString( + &pixmapName, &tline[clength + 7]); + if (pixmapName[0] == 0) { + free(pixmapName); + pixmapName = (char *)0; + } + } + continue; + } + if (strncasecmp(tline, + CatString3("*", myName, "Timeout"), + clength + 8) == 0) { + timeout = atoi(&tline[clength + 8]) * 1000000; + continue; + } + if (strncasecmp(tline, "PixmapPath", 10) == 0) { + CopyString(&pixmapPath, &tline[10]); + if (pixmapPath[0] == 0) { + free(pixmapPath); + pixmapPath = (char *)0; + } + continue; + } + } } - continue; - } - if (strncasecmp (tline, - CatString3 ("*", myName, "Timeout"), - clength + 8) ==0) - { - timeout = atoi(&tline[clength+8]) * 1000000; - continue; - } - if (strncasecmp(tline, "PixmapPath",10)==0) - { - CopyString (&pixmapPath, &tline[10]); - if (pixmapPath[0] == 0) - { - free (pixmapPath); - pixmapPath = (char *) 0; - } - continue; - } - } - } - return; + return; } /************************************************************************** * Change the window name displayed in the title bar. **************************************************************************/ -void change_window_name(char *str) +void +change_window_name(char *str) { - XTextProperty name; - - if (XStringListToTextProperty(&str,1,&name) == 0) - { - fprintf(stderr,"FvwmBanner: cannot allocate window name"); - return; - } - XSetWMName(dpy,win,&name); - XSetWMIconName(dpy,win,&name); - XFree(name.value); -} + XTextProperty name; + if (XStringListToTextProperty(&str, 1, &name) == 0) { + fprintf(stderr, "FvwmBanner: cannot allocate window name"); + return; + } + XSetWMName(dpy, win, &name); + XSetWMIconName(dpy, win, &name); + XFree(name.value); +} /*********************************************************************** * @@ -370,8 +338,8 @@ void change_window_name(char *str) ***********************************************************************/ /*ARGSUSED*/ -void DeadPipe (int nonsense) +void +DeadPipe(int nonsense) { - exit (0); + exit(0); } - Index: fvwm/modules/FvwmButtons/BUGS =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/BUGS,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/BUGS --- fvwm/modules/FvwmButtons/BUGS +++ fvwm/modules/FvwmButtons/BUGS @@ -16,30 +16,3 @@ Known bugs as of FvwmButtons-080396: debug on this; DEBUG_HANGON. There has also been reported problems with buttons hanging forever after being pressed, this might be related. - - * When you make the buttonbox small enough (= very small, less than 1x1 - pixel inside relief and padding) it exits. Should make it silently suffer - with grace instead. Update: actually this is a problem with the swallowed - windows, some crash when made 1x1. Otherwise the rest is fixed. - -Known bugs as of FvwmButtons-070396: - - * Action commands are supposed to work also on swallowed windows, but there - is a problem with X. After reparenting, XSelectInput is called with a mask - including ButtonPressMask|ButtonReleaseMask, but evidently no buttonpresses - are received, even though the program (like xload) doesn't use them for - itself. So where is the bottleneck? Send the solution if you got it. - OK, so I need to do SubstructureRedirectMask, and shuffle all the events - onwards... really? No better way? Mmm.. - -Known bugs as of FvwmButtons-040396: - - * There are still some problems related to swallowed windows, but I haven't - found a reliable way to reproduce them. What probably happens is that a - window is created, FvwmButtons gets its name and desides to swallow it, it - is mapped, but before it gets swallowed it fails, thus the reparent code - does a BadWindow. - - * When you kill many swallowed windows quickly, FvwmButtons crashes probably - because after gracefully removing one of it's children it tries to redraw - some other before handling more destroy_requests. Index: fvwm/modules/FvwmButtons/FvwmButtons.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/FvwmButtons.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/FvwmButtons.1 --- fvwm/modules/FvwmButtons/FvwmButtons.1 +++ fvwm/modules/FvwmButtons/FvwmButtons.1 @@ -1,49 +1,43 @@ .\" $OpenBSD: FvwmButtons.1,v 1.1.1.1 2006/11/26 10:53:44 matthieu Exp $ .\" t # I don't know this stuff, sorry. -Jarl .\" @(#)FvwmButtons.1 1/28/94 -.TH FvwmButtons 1 "Nov 1 1998" +.TH FVWMBUTTONS 1 "November 1, 1998" "2.0.41" "FVWM Modules" .UC .SH NAME FvwmButtons \- the FVWM buttonbox module .SH SYNOPSIS FvwmButtons is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION The FvwmButtons module provides a window of buttons which sits on the X terminal's root window. The user can press the buttons at any time, and trigger invocation of a user-specified command by the window manager. FvwmButtons only works when fvwm is used as the window manager. - +.PP The buttonbox can be of any configuration or geometry, and can have -monochrome or color icons to represent the actions which would be -invoked. - +monochrome or color icons to represent the actions which would be invoked. .SH INITIALIZATION During initialization, \fIFvwmButtons\fP will search for a configuration -file which describes the buttonbox geometry, color, icons, and -actions. The format of -this files will be described later. The configuration file will be the -one which fvwm used during its initialization. - -To use FvwmButtons with several different configurations, you can -invoke FvwmButtons with an optional parameter, which it will use +file which describes the buttonbox geometry, color, icons, and actions. The +format of this file will be described later. The configuration file will be +the one which fvwm used during its initialization. +.PP +To use FvwmButtons with several different configurations, you can invoke +FvwmButtons with an optional parameter, which it will use as its name instead (e.g "Module FvwmButtons SomeButtons"). SomeButtons will then read only the lines in the configuration file starting with "*SomeButtons", and not the lines belonging to FvwmButtons. - +.PP You can also specify an optional configuration file to use instead of the default fvwm configuration file, by giving a second argument which is a filename. This will override the setting "*FvwmButtonsFile", see below. - .SH INVOCATION FvwmButtons can be invoked by inserting the line 'Module FvwmButtons' in the .fvwmrc file. This should be placed in the InitFunction if FvwmButtons -is to be spawned during fvwm's initialization, or can be bound to a -menu or mouse button or keystroke to invoke it later. Fvwm will search -directory specified in the ModulePath configuration option to attempt -to locate FvwmButtons. - +is to be spawned during fvwm's initialization, or can be bound to a menu +or mouse button or keystroke to invoke it later. Fvwm will search directory +specified in the ModulePath configuration option to attempt to locate +FvwmButtons. .SH CONFIGURATION OPTIONS The following options int the .fvwmrc file are understood by FvwmButtons: .IP "*FvwmButtonsBack \fIcolor\fP" @@ -123,10 +117,11 @@ Specifies an fvwm command to be executed when the button is activated by pressing return or a mouse button. The \fIcommand\fP needs to be quoted if it contains a comma or a closing parenthesis. The current options are: - -Mouse \fIn\fP - this action is only executed for mouse button \fIn\fP. -One actions can be defined for each mouse button, in addition to the -general action. +.RS +.IP "Mouse \fIn\fP" +This action is only executed for mouse button \fIn\fP. One action can be +defined for each mouse button, in addition to the general action. +.RE .IP " Back \fIcolor\fP" Specifies the background color to be used drawing this box. A relief color and a shadow color will also be calculated from this. @@ -143,24 +138,24 @@ be set with \fITitle(flags)\fP and \fISwallow(flags)\fP. You should also specify either "Columns \fIwidth\fP" or "Rows \fIheight\fP", or "Rows 2" will be assumed for purpose of arranging the buttons inside the container. For an example, see the \fISample configuration\fP section. - +.PP The container button itself (separate from the contents) can take format -options like -\fIFrame\fP and \fIPadding\fP, and commands can be bound to it. This means -you can make a sensitive relief around a container, like - - *FvwmButtons(2x2, Frame 5, Padding 2 2, Action Beep,\\ - Container(Frame 1)) - +options like \fIFrame\fP and \fIPadding\fP, and commands can be bound to it. +This means you can make a sensitive relief around a container, like +.EX +*FvwmButtons(2x2, Frame 5, Padding 2 2, Action Beep,\ + Container(Frame 1)) +.EE +.PP Typically you will want to at least give the container a size setting \fIwidth\fPx\fIheight\fP. - .IP " End" Specifies that no more buttons are defined for the current container, and further buttons will be put in the container's parent. This option should be given on a line by itself, i.e - - *FvwmButtons(End) +.EX +*FvwmButtons(End) +.EE .IP " Font \fIfontname\fP" Specifies that the font \fIfontname\fP is to be used for labeling this button. .IP " Fore \fIcolor\fP" @@ -213,60 +208,62 @@ larger sizes. Causes FvwmButtons to execute \fIcommand\fP, and when a window matching the name \fIhangon\fP appears, it is captured and swallowed into this button. An example: - - *FvwmButtons(Swallow XClock 'Exec xclock &') - -will take the first window whose name, class or resource is "XClock" and -display it in the button. Modules can be swallowed by specifying -the module instead of 'Exec whatever', like: - - *FvwmButtons(Swallow "FvwmPager" "FvwmPager 0 0") - +.EX +*FvwmButtons(Swallow XClock 'Exec xclock &') +.EE +.PP +This takes the first window whose name, class or resource is "XClock" and +displays it in the button. Modules can be swallowed by specifying the module +instead of 'Exec whatever', like: +.EX +*FvwmButtons(Swallow "FvwmPager" "FvwmPager 0 0") +.EE +.PP The flags that can be given to swallow are: - -NoClose / Close - +.RS +.IP "NoClose / Close" Specifies whether the swallowed program in this button will be unswallowed -or closed when FvwmButtons exit cleanly. "NoClose" can be combined with -"UseOld" to have windows survive restart of windowmanager. The default +or closed when FvwmButtons exits cleanly. "NoClose" can be combined with +"UseOld" to have windows survive restart of the window manager. The default setting is "Close". - -NoHints / Hints - -Specifies whether hints from the swallowed program in this -button will be ignored or not, useful in forcing a window to resize itself -to fit its button. The default value is "Hints". - -NoKill / Kill - +.IP "NoHints / Hints" +Specifies whether hints from the swallowed program in this button will be +ignored or not, useful in forcing a window to resize itself to fit its +button. The default value is "Hints". +.IP "NoKill / Kill" Specifies whether the swallowed program will be closed by killing it or by -sending a message to it. This can be useful in ending programs that -doesn't accept window manager protocol. The default value is "NoKill". -This has no effect if "NoClose" is specified. - -NoRespawn / Respawn - -Specifies whether the swallowed program is to be respawn if it dies. +sending a message to it. This can be useful in ending programs that do not +accept window manager protocol. The default value is "NoKill". This has no +effect if "NoClose" is specified. +.IP "NoRespawn / Respawn" +Specifies whether the swallowed program is to be respawned if it dies. If "Respawn" is specified, the program will be respawned using the original \fIcommand\fP. Use this option with care, the program might have a very legitimate reason to die. - -NoOld / UseOld - +.IP "NoOld / UseOld" Specifies whether the button will try to swallow an existing window matching the \fIhangon\fP name before spawning one itself with \fIcommand\fP. -The default value is "NoOld". -"UseOld" can be combined with "NoKill" to have windows survive restart of -windowmanager. If you want FvwmButtons to swallow an old window, and not -spawn one itself if failing, let the \fIcommand\fP be "Nop": - - *FvwmButtons(Swallow (UseOld) "Console" Nop) - +The default value is "NoOld". "UseOld" can be combined with "NoKill" to +have windows survive restart of the window manager. If you want FvwmButtons +to swallow an old window, and not spawn one itself if failing, let the +\fIcommand\fP be "Nop": +.EX +*FvwmButtons(Swallow (UseOld) "Console" Nop) +.EE +.RE +.PP If you want to be able to start it yourself, combine it with an action: - - *FvwmButtons(Swallow (UseOld) "Console" Nop, \\ - Action `Exec "Console" console &`) - -NoTitle / UseTitle - +.EX +*FvwmButtons(Swallow (UseOld) "Console" Nop, \ + Action `Exec "Console" console &`) +.EE +.PP +.RS +.IP "NoTitle / UseTitle" Specifies whether the title of the button will be taken from the swallowed window's title or not. If "UseTitle" is given, the title on the button will change dynamically to reflect the window name. The default is "NoTitle". - +.RE .IP " Title [(\fIoptions\fP)] \fIname\fP" Specifies the title which will be written on the button. Whitespace can be included in the title by quoting it. @@ -275,17 +272,19 @@ its buttons, characters are chopped of one at a time until it fits. If \fIjustify\fP is "Right", the head is removed, otherwise its tail is removed. These \fIoptions\fP can be given to Title: - -Center - The title will be centered horizontally. This is the default. - -Left - The title will be justified to the left side. - -Right - The title will be justified to the right side. - -Side - This will cause the title to appear on the right hand side of -any icon or swallowed window, instead of below it which is the default. -If you use small icons, and combine this with the "Left" option, you can -get a look similar to fvwm's menus. +.RS +.IP Center +The title will be centered horizontally. This is the default. +.IP Left +The title will be justified to the left side. +.IP Right +The title will be justified to the right side. +.IP Side +This will cause the title to appear on the right-hand side of any icon or +swallowed window, instead of below it which is the default. If you use small +icons, and combine this with the "Left" option, you can get a look similar to +fvwm's menus. +.RE .IP "Legacy fields [\fItitle icon command\fP]" These fields are kept for compatibility with previous versions of FvwmButtons, and their use is discouraged. @@ -299,15 +298,16 @@ Action \fIcommand\fP or alternatively Swallow "\fIhangon\fP" \fIcommand\fP. Any fvwm command is recognized by FvwmButtons. See fvwm(1) for more info on this. The Exec command has a small extension when used in Actions, its syntax is here: - - Exec ["hangon"] command - +.EX +Exec ["hangon"] command +.EE +.PP When FvwmButtons finds such an Exec command, the button will remain pushed in until a window whose name or class matches the qouted portion of the command is encountered. This is intended to provide visual feedback to the user that the action he has requested -will be performed. If the qouted portion -contains no characters, then the button will pop out immediately. +will be performed. If the qouted portion contains no characters, then the +button will pop out immediately. Note that users can continue pressing the button, and re-executing the command, even when it looks "pressed in." .IP "Quoting" @@ -316,31 +316,31 @@ earlier versions commands no longer need to be quoted. In this case any quoting character will be passed on to the application untouched. Only commas ',' and closing parentheses ')' have to be quoted inside a command. -Quoting can be done with any of the three quotation characters; -single quote: - - 'This is a "quote"', - +Quoting can be done with any of the three quotation characters; single +quote: +.EX +\&'This is a "quote"', +.EE +.PP double quote: - - "It's another `quote'", - +.EX +\&"It's another `quote'", +.EE +.PP and backquote: - - `This is a strange quote`. - -The backquoting is purposeful -if you use a preprocessor like FvwmCpp and want it to get into your -commands, like this: - - #define BG gray60 - *FvwmButtons(Swallow "xload" `Exec xload -bg BG &`) - -Furthermore a single character can be quoted with a preceding -backslash '\'. - +.EX +`This is a strange quote`. +.EE +.PP +The backquoting is purposeful if you use a preprocessor like FvwmCpp and +want it to get into your commands, like this: +.EX +#define BG gray60 +*FvwmButtons(Swallow "xload" `Exec xload -bg BG &`) +.EE +.PP +Furthermore a single character can be quoted with a preceding backslash '\'. .SH ARRANGEMENT ALGORITHM - FvwmButtons tries to arrange its buttons as best it can, by using recursively, on each container including the buttonbox itself, the following algorithm. @@ -379,28 +379,27 @@ are placed if necessary if the BoxSize option \fIsmart\fP is used. Containers are arranged by the same algorithm, in fact they are shuffled recursively as the algorithm finds them. .IP "Clarifying example" -An example might be useful here: Suppose you have 6 buttons, all unit sized -except number two, which is 2x2. This makes for 5 times 1 plus 1 times 4 -equals 9 unit buttons total area. Assume you have requested 3 columns. -.nf -.sp +An example might be useful here: Suppose you have six buttons, all unit +sized except number two, which is 2x2. This makes for five times 1 plus one +times 4 equals nine unit buttons total area. Assume you have requested three +columns. +.EX 1) +---+---+---+ 2) +---+---+---+ 3) +---+---+---+ - | 1 | | | 1 | | | 1 | | - +---+ + +---+ 2 + +---+ 2 + - | | | | | | 3 | | - + + + +---+---+ +---+---+---+ - | | | | | | | | - +-----------+ +---+-------+ +---+---+---+ + | 1 | | | 1 | | | 1 | | + +---+ + +---+ 2 + +---+ 2 + + | | | | | | 3 | | + + + + +---+---+ +---+---+---+ + | | | | | | | | + +-----------+ +---+-------+ +---+---+---+ 4) +---+---+---+ 5) +---+-------+ 6) +---+-------+ - | 1 | | | 1 | | | 1 | | - +---+ 2 + +---+ 2 | +---+ 2 | - | 3 | | | 3 | | | 3 | | - +---+---+---+ +---+---+---+ +---+-------+ - | 4 | | | 4 | 5 | | | 4 | 5 | 6 | - +---+---+---+ +---+---+---+ +---+---+---+ -.sp -.fi + | 1 | | | 1 | | | 1 | | + +---+ 2 + +---+ 2 | +---+ 2 | + | 3 | | | 3 | | | 3 | | + +---+---+---+ +---+---+---+ +---+---+---+ + | 4 | | | 4 | 5 | | | 4 | 5 | 6 | + +---+---+---+ +---+---+---+ +---+---+---+ +.EE .IP "What size will the buttons be?" When FvwmButtons has read the icons and fonts that are required by its configuration, it can find out which size is needed for every non-swallowing @@ -412,13 +411,10 @@ for a swallowed window, it can be set in that button's configuration line using the option "Size \fIwidth height\fP". This will tell FvwmButtons to give this button at least \fIwidth\fP by \fIheight\fP pixels inside the relief and padding. - .SH SAMPLE CONFIGURATION The following are excepts from a .fvwmrc file which describe FvwmButtons initialization commands: - -.nf -.sp +.EX XCOMM######################################################### XCOMM Load any modules which should be started during fvwm XCOMM initialization @@ -474,22 +470,20 @@ XCOMM######################################################### *FvwmButtons(Swallow(UseOld,NoKill) "xload15" `Exec xload \\ -title xload15 -nolabel -bg rgb:90/80/90 -update 15 &`) -.sp -.fi - +.EE +.PP The last lines are a little tricky - one spawns an FvwmPager module, and captures it to display in a quadruple width button. -is used, the Pager will be as big as possible within the button's relief. - +If this is used, the Pager will be as big as possible within the button's +relief. +.PP The final line is even more magic. Note the combination of \fIUseOld\fP and \fINoKill\fP, which will try to swallow an existing window with the name "xload15" when starting up (if failing: starting one with the specified command), which is unswallowed when ending FvwmButtons. - +.PP The other panels are specified after the root panel: - -.nf -.sp +.EX XCOMM######### PANEL *FvwmButtonsPanel WinOps *FvwmButtonsBack bisque2 @@ -508,21 +502,19 @@ XCOMM######### PANEL *FvwmButtonsColumns 1 *FvwmButtons(Title Kill ,Icon bomb.xpm ,Action Destroy) -.sp -.fi - +.EE +.PP The color specification \fIrgb:90/80/90\fP is actually the most correct way of specifying independent colors in X, and should be used instead of the older \fI#908090\fP. If the latter specification is used in your configuration file, you should be sure to escape the hash in any of the \fIcommand\fPs which will be executed, or fvwm will consider the rest of the line a comment. - +.PP Note that with the x/y geometry specs you can easily build button windows with gaps. Here is another example. You can not accomplish this without geometry specs for the buttons: -.nf -.sp +.EX XCOMM######################################################### XCOMM Make it titlebar-less, sticky, and give it an icon @@ -565,26 +557,18 @@ XCOMM big items *FvwmButtons(20x5, Padding 0, Swallow "xosview" \\ `Exec /usr/X11R6/bin/xosview -cpu -int -page -net \\ -geometry 100x50+0-0 -font 5x7`) -.sp -.fi - -.SH BUGS - -The action part of the Swallow option must be quoted if it contains -any whitespace character. - +.EE .SH COPYRIGHTS -The FvwmButtons program, and the concept for interfacing this module to -the Window Manager, are all original work by Robert Nation - -Copyright 1993, Robert Nation. No guarantees or warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - -Further modifications and patching by Jarl Totland, copyright 1996. -The statement above still applies. - +The FvwmButtons program, and the concept for interfacing this module to the +Window Manager, are all original work by Robert Nation. +.PP +Copyright 1993, Robert Nation. No guarantees or warranties or anything are +provided or implied in any way whatsoever. Use this program at your own risk. +Permission to use this program for any purpose is given, as long as the +copyright is kept intact. +.PP +Further modifications and patching by Jarl Totland, copyright 1996. The +statement above still applies. .SH AUTHOR Robert Nation. Somewhat enhanced by Jarl Totland, Jui-Hsuan Joshua Feng and Dominik Vogt. Index: fvwm/modules/FvwmButtons/FvwmButtons.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/FvwmButtons.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/FvwmButtons.c --- fvwm/modules/FvwmButtons/FvwmButtons.c +++ fvwm/modules/FvwmButtons/FvwmButtons.c @@ -14,32 +14,32 @@ /* ------------------------------- includes -------------------------------- */ #include "config.h" +#include "../../fvwm/fvwm_sandbox.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include +#include +#include +#include + #include -#include -#include -#include #include +#include +#include +#include #include -#include -#include -#include +#include #ifdef HAVE_SYS_SELECT_H #include #endif -#include +#include +#include #include -#include #include -#include -#include +#include +#include #ifdef XPM #include #endif @@ -50,59 +50,62 @@ #include "../../fvwm/module.h" #include "../../libs/fvwmlib.h" #include "FvwmButtons.h" -#include "misc.h" /* ConstrainSize() */ -#include "parse.h" /* ParseOptions() */ -#include "icons.h" /* CreateIconWindow(), ConfigureIconWindow() */ #include "draw.h" +#include "icons.h" /* CreateIconWindow(), ConfigureIconWindow() */ +#include "misc.h" /* ConstrainSize() */ +#include "parse.h" /* ParseOptions() */ - -#define MW_EVENTS (ExposureMask |\ - StructureNotifyMask |\ - ButtonReleaseMask | ButtonPressMask |\ - KeyReleaseMask | KeyPressMask) +#define MW_EVENTS \ + (ExposureMask | StructureNotifyMask | ButtonReleaseMask | \ + ButtonPressMask | KeyReleaseMask | KeyPressMask) /* SW_EVENTS are for swallowed windows... */ -#define SW_EVENTS (PropertyChangeMask | StructureNotifyMask |\ - ResizeRedirectMask | SubstructureNotifyMask) +#define SW_EVENTS \ + (PropertyChangeMask | StructureNotifyMask | ResizeRedirectMask |\ + SubstructureNotifyMask | ButtonPressMask | ButtonReleaseMask) #ifdef DEBUG_FVWM -#define MySendText(a,b,c) {\ - fprintf(stderr,"%s: Sending text to fvwm: \"%s\"\n",MyName,(b));\ - SendText((a),(b),(c));} +#define MySendText(a, b, c) \ + { \ + fprintf(stderr, "%s: Sending text to fvwm: \"%s\"\n", MyName,\ + (b)); \ + SendText((a), (b), (c)); \ + } #else -#define MySendText(a,b,c) SendText((a),(b),(c)); +#define MySendText(a, b, c) SendText((a), (b), (c)); #endif /* --------------------------- external functions -------------------------- */ -extern void DumpButtons(button_info*); -extern void SaveButtons(button_info*); +extern void DumpButtons(button_info *); +extern void SaveButtons(button_info *); /* ------------------------------ prototypes ------------------------------- */ void DeadPipe(int nonsense) __attribute__((__noreturn__)); static void DeadPipeCleanup(void); -static RETSIGTYPE TerminateHandler(int sig); -void SetButtonSize(button_info*,int,int); +static void TerminateHandler(int sig); +void SetButtonSize(button_info *, int, int); /* main */ void Loop(void); -void RedrawWindow(button_info*); -void RecursiveLoadData(button_info*,int*,int*); -void CreateWindow(button_info*,int,int); +void RedrawWindow(button_info *); +void RecursiveLoadData(button_info *, int *, int *); +void CreateWindow(button_info *, int, int); void nocolor(const char *a, const char *b) __attribute__((__noreturn__)); Pixel GetColor(char *name); int My_XNextEvent(Display *dpy, XEvent *event); -void process_message(unsigned long type,unsigned long *body); -extern void send_clientmessage (Display *disp, Window w, Atom a, Time timestamp); -void CheckForHangon(unsigned long*); -Window GetRealGeometry(Display*,Window,int*,int*,ushort*,ushort*, - ushort*,ushort*); -void swallow(unsigned long*); -void AddButtonAction(button_info*,int,char*); -char *GetButtonAction(button_info*,int); +void process_message(unsigned long type, unsigned long *body); +extern void send_clientmessage(Display *disp, Window w, Atom a, Time timestamp); +void CheckForHangon(unsigned long *); +Window GetRealGeometry( + Display *, Window, int *, int *, ushort *, ushort *, ushort *, ushort *); +void swallow(unsigned long *); +void AddButtonAction(button_info *, int, char *); +char *GetButtonAction(button_info *, int); -void DebugEvents(XEvent*); +void DebugEvents(XEvent *); panel_info *seekpanel(button_info *); void Slide(panel_info *, button_info *); +static int IOErrorHandler(Display *dpy); /* -------------------------------- globals ---------------------------------*/ @@ -114,7 +117,7 @@ XFontStruct *font; int screen; int d_depth; -int x_fd,fd_width; +int x_fd, fd_width; char *config_file = NULL; @@ -124,10 +127,10 @@ char *iconPath = NULL; char *pixmapPath = NULL; Pixel hilite_pix, back_pix, shadow_pix, fore_pix; -GC NormalGC; -int Width,Height; +GC NormalGC; +int Width, Height; -int x= -30000,y= -30000,w= -1,h= -1,gravity = NorthWestGravity; +int x = -30000, y = -30000, w = -1, h = -1, gravity = NorthWestGravity; int new_desk = 0; int ready = 0; int xneg = 0, yneg = 0; @@ -135,43 +138,36 @@ int xneg = 0, yneg = 0; button_info *CurrentButton = NULL; int fd[2]; -button_info *UberButton=NULL; +button_info *UberButton = NULL; panel_info *MainPanel = NULL, *CurrentPanel = NULL, *PanelIndex; int dpw, dph; -int save_color_limit; /* Color limit, if any */ +int save_color_limit; /* Color limit, if any */ static volatile sig_atomic_t isTerminated = False; +static volatile sig_atomic_t connection_dead = False; /* ------------------------------ Misc functions ----------------------------*/ -#ifdef DEBUG -char *mymalloc(int length) -{ - int i=length; - char *p=safemalloc(length); - while(i) - p[--i]=255; - return p; -} -#endif - /** *** Some fancy routines straight out of the manual :-) Used in DeadPipe. **/ -Bool DestroyedWindow(Display *d,XEvent *e,char *a) +Bool +DestroyedWindow(Display *d, XEvent *e, char *a) { - if(e->xany.window == (Window)a) - if((e->type == DestroyNotify && e->xdestroywindow.window == (Window)a)|| - (e->type == UnmapNotify && e->xunmap.window == (Window)a)) - return True; - return False; + if (e->xany.window == (Window)a) + if ((e->type == DestroyNotify && + e->xdestroywindow.window == (Window)a) || + (e->type == UnmapNotify && e->xunmap.window == (Window)a)) + return True; + return False; } -int IsThereADestroyEvent(button_info *b) + +int +IsThereADestroyEvent(button_info *b) { - XEvent event; - Bool DestroyedWindow(); - return XCheckIfEvent(Dpy,&event,DestroyedWindow,(char*)b->IconWin); + XEvent event; + return XCheckIfEvent(Dpy, &event, DestroyedWindow, (char *)b->IconWin); } /** @@ -179,205 +175,205 @@ int IsThereADestroyEvent(button_info *b) *** Externally callable function to quit! Note that DeadPipeCleanup *** is an exit-procedure and so will be called automatically **/ -void DeadPipe(int whatever) +void +DeadPipe(int whatever) { - exit(0); + exit(0); } /** *** TerminateHandler() *** Signal handler that will make the event-loop terminate **/ -static RETSIGTYPE +static void TerminateHandler(int sig) { - isTerminated = True; + isTerminated = True; } /** *** DeadPipeCleanup() *** Remove all the windows from the Button-Bar, and close them as necessary **/ -static void DeadPipeCleanup(void) +static void +DeadPipeCleanup(void) { - button_info *b,*ub=UberButton; - int button=-1; - - signal(SIGPIPE, SIG_IGN);/* Xsync may cause SIGPIPE */ - - XSync(Dpy,0); /* Wait for thing to settle down a bit */ - XGrabServer(Dpy); /* We don't want interference right now */ - while(NextButton(&ub,&b,&button,0)) - { - /* delete swallowed windows */ - if((buttonSwallowCount(b)==3) && b->IconWin) - { -# ifdef DEBUG_HANGON - fprintf(stderr,"%s: Button 0x%06x window 0x%x (\"%s\") is ", - MyName,(ushort)b,(ushort)b->IconWin,b->hangon); -# endif - if(!IsThereADestroyEvent(b)) { /* Has someone destroyed it? */ - if(!(buttonSwallow(b)&b_NoClose)) - { - if(buttonSwallow(b)&b_Kill) - { - XKillClient(Dpy,b->IconWin); -# ifdef DEBUG_HANGON - fprintf(stderr,"now killed\n"); -# endif - } - else - { - send_clientmessage(Dpy,b->IconWin,_XA_WM_DEL_WIN, - CurrentTime); -# ifdef DEBUG_HANGON - fprintf(stderr,"now deleted\n"); -# endif - } - } - else - { -# ifdef DEBUG_HANGON - fprintf(stderr,"now unswallowed\n"); -# endif - XReparentWindow(Dpy,b->IconWin,Root,b->x,b->y); - XMoveWindow(Dpy,b->IconWin,b->x,b->y); - XResizeWindow(Dpy,b->IconWin,b->w,b->h); - XSetWindowBorderWidth(Dpy,b->IconWin,b->bw); - } - } -# ifdef DEBUG_HANGON - else - fprintf(stderr,"already handled\n"); -# endif + button_info *b, *ub = UberButton; + int button = -1; + + if (connection_dead) + return; + + signal(SIGPIPE, SIG_IGN); /* Xsync may cause SIGPIPE */ + + XSync(Dpy, 0); /* Wait for thing to settle down a bit */ + XGrabServer(Dpy); /* We don't want interference right now */ + while (NextButton(&ub, &b, &button, 0)) { + /* delete swallowed windows */ + if ((buttonSwallowCount(b) == 3) && b->IconWin) { +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x window 0x%x (\"%s\") is ", + MyName, (ushort)b, (ushort)b->IconWin, b->hangon); +#endif + if (!IsThereADestroyEvent( + b)) { /* Has someone destroyed it? */ + if (!(buttonSwallow(b) & b_NoClose)) { + if (buttonSwallow(b) & b_Kill) { + XKillClient(Dpy, b->IconWin); +#ifdef DEBUG_HANGON + fprintf(stderr, "now killed\n"); +#endif + } else { + send_clientmessage(Dpy, + b->IconWin, _XA_WM_DEL_WIN, + CurrentTime); +#ifdef DEBUG_HANGON + fprintf( + stderr, "now deleted\n"); +#endif + } + } else { +#ifdef DEBUG_HANGON + fprintf(stderr, "now unswallowed\n"); +#endif + XReparentWindow( + Dpy, b->IconWin, Root, b->x, b->y); + XMoveWindow( + Dpy, b->IconWin, b->x, b->y); + XResizeWindow( + Dpy, b->IconWin, b->w, b->h); + XSetWindowBorderWidth( + Dpy, b->IconWin, b->bw); + } + } +#ifdef DEBUG_HANGON + else + fprintf(stderr, "already handled\n"); +#endif + } + } + XUngrabServer(Dpy); /* We're through */ + XSync(Dpy, + 0); /* Let it all die down again so we can catch our X errors... */ + + /* Hey, we have to free the pictures too! */ + button = -1; + ub = UberButton; + while (NextButton(&ub, &b, &button, 1)) { + if (b->flags & b_Icon) + DestroyPicture(Dpy, b->icon); + if (b->flags & b_IconBack) + DestroyPicture(Dpy, b->backicon); + if (b->flags & b_Container && b->c->flags & b_IconBack && + !(b->c->flags & b_TransBack)) + DestroyPicture(Dpy, b->c->backicon); } - } - XUngrabServer(Dpy); /* We're through */ - XSync(Dpy,0); /* Let it all die down again so we can catch our X errors... */ - - /* Hey, we have to free the pictures too! */ - button=-1;ub=UberButton; - while(NextButton(&ub,&b,&button,1)) - { - if(b->flags&b_Icon) - DestroyPicture(Dpy,b->icon); - if(b->flags&b_IconBack) - DestroyPicture(Dpy,b->backicon); - if(b->flags&b_Container && b->c->flags&b_IconBack - && !(b->c->flags&b_TransBack)) - DestroyPicture(Dpy,b->c->backicon); - } } /** *** SetButtonSize() *** Propagates global geometry down through the buttonhierarchy. **/ -void SetButtonSize(button_info *ub,int w,int h) +void +SetButtonSize(button_info *ub, int w, int h) { - int i=0,dx,dy; - if(!ub || !(ub->flags&b_Container)) - { - fprintf(stderr,"%s: BUG: Tried to set size of noncontainer\n",MyName); - exit(2); - } - if(ub->c->num_rows==0 || ub->c->num_columns==0) - { - fprintf(stderr,"%s: BUG: Set size when rows/cols was unset\n",MyName); - exit(2); - } - w*=ub->BWidth; - h*=ub->BHeight; - - if(ub->parent) - { - i=buttonNum(ub); - ub->c->xpos=buttonXPos(ub,i); - ub->c->ypos=buttonYPos(ub,i); - } - dx=buttonXPad(ub)+buttonFrame(ub); - dy=buttonYPad(ub)+buttonFrame(ub); - ub->c->xpos+=dx; - ub->c->ypos+=dy; - w-=2*dx; - h-=2*dy; - ub->c->ButtonWidth=w/ub->c->num_columns; - ub->c->ButtonHeight=h/ub->c->num_rows; - - i=0; - while(ic->num_buttons) - { - if(ub->c->buttons[i] && ub->c->buttons[i]->flags&b_Container) - SetButtonSize(ub->c->buttons[i], - ub->c->ButtonWidth,ub->c->ButtonHeight); - i++; - } -} + int i = 0, dx, dy; + if (!ub || !(ub->flags & b_Container)) { + fprintf(stderr, "%s: BUG: Tried to set size of noncontainer\n", + MyName); + exit(2); + } + if (ub->c->num_rows == 0 || ub->c->num_columns == 0) { + fprintf(stderr, "%s: BUG: Set size when rows/cols was unset\n", + MyName); + exit(2); + } + w *= ub->BWidth; + h *= ub->BHeight; + if (ub->parent) { + i = buttonNum(ub); + ub->c->xpos = buttonXPos(ub, i); + ub->c->ypos = buttonYPos(ub, i); + } + dx = buttonXPad(ub) + buttonFrame(ub); + dy = buttonYPad(ub) + buttonFrame(ub); + ub->c->xpos += dx; + ub->c->ypos += dy; + w -= 2 * dx; + h -= 2 * dy; + ub->c->ButtonWidth = w / ub->c->num_columns; + ub->c->ButtonHeight = h / ub->c->num_rows; + + i = 0; + while (i < ub->c->num_buttons) { + if (ub->c->buttons[i] && ub->c->buttons[i]->flags & b_Container) + SetButtonSize(ub->c->buttons[i], ub->c->ButtonWidth, + ub->c->ButtonHeight); + i++; + } +} /** *** AddButtonAction() **/ -void AddButtonAction(button_info *b,int n,char *action) +void +AddButtonAction(button_info *b, int n, char *action) { - int l; - char *s; - char *t; - - if(!b || n<0 || n>3 || !action) - { - fprintf(stderr,"%s: BUG: AddButtonAction failed\n",MyName); - exit(2); - } - if(b->flags&b_Action) - { - if(b->action[n]) - free(b->action[n]); - } - else - { - int i; - b->action=(char**)mymalloc(4*sizeof(char*)); - for(i=0;i<4;b->action[i++]=NULL); - b->flags|=b_Action; - } - - while (*action && isspace(*action)) - action++; - l = strlen(action); - if (l > 1) - { - switch (action[0]) - { - case '\"': - case '\'': - case '`': - s = SkipQuote(action, NULL, "", ""); - /* Strip outer quotes */ - if (*s == 0) - { - action++; - l -= 2; - } - break; - default: - break; - } - } - t = (char *)mymalloc(l + 1); - memmove(t, action, l); - t[l] = 0; - b->action[n] = t; + int l; + char *s; + char *t; + + if (!b || n < 0 || n > 3 || !action) { + fprintf(stderr, "%s: BUG: AddButtonAction failed\n", MyName); + exit(2); + } + if (b->flags & b_Action) { + if (b->action[n]) + free(b->action[n]); + } else { + int i; + b->action = (char **)xmalloc(4 * sizeof(char *)); + for (i = 0; i < 4; b->action[i++] = NULL) + ; + b->flags |= b_Action; + } + + while (*action && isspace(*action)) + action++; + l = strlen(action); + if (l > 1) { + switch (action[0]) { + case '\"': + case '\'': + case '`': + s = SkipQuote(action, NULL, "", ""); + /* Strip outer quotes */ + if (*s == 0) { + action++; + l -= 2; + } + break; + default: + break; + } + } + t = (char *)xmalloc(l + 1); + memmove(t, action, l); + t[l] = 0; + b->action[n] = t; } /** *** GetButtonAction() **/ -char *GetButtonAction(button_info *b,int n) +char * +GetButtonAction(button_info *b, int n) { - if(!b || !(b->flags&b_Action) || !(b->action) || n<0 || n>3) - return NULL; - return b->action[n]; + if (!b || !(b->flags & b_Action) || !(b->action) || n < 0 || n > 3) + return NULL; + return b->action[n]; } #ifdef SHAPE @@ -386,71 +382,69 @@ char *GetButtonAction(button_info *b,int n) *** use the Shape extension to create a transparent background. *** Patrice Fortier **/ -void SetTransparentBackground(button_info *ub,int w,int h) +void +SetTransparentBackground(button_info *ub, int w, int h) { - Pixmap pmap_mask; - button_info *b; - GC gc; - XGCValues gvals; - unsigned long gcm=0; - Window root_return; - int x_return, y_return; - unsigned int width_return, height_return; - unsigned int border_width_return; - unsigned int depth_return; - int number, i; - XFontStruct *font; - - pmap_mask = XCreatePixmap(Dpy,MyWindow,w,h,1); - gc = XCreateGC(Dpy,pmap_mask,(unsigned long)0,&gvals); - XSetForeground(Dpy,gc,0); - XFillRectangle(Dpy,pmap_mask,gc,0,0,w,h); - XSetForeground(Dpy,gc,1); - - /* - * if button has an icon, draw a rect with the same size as the icon - * (or the mask of the icon), - * else draw a rect with the same size as the button. - */ - - i=-1; - while(NextButton(&ub,&b,&i,0)) - { - if(b->flags&b_Icon) - { - XGetGeometry(Dpy,b->IconWin,&root_return,&x_return,&y_return, - &width_return,&height_return, - &border_width_return,&depth_return); - - number=buttonNum(b); - if (b->icon->mask == None) - XFillRectangle(Dpy,pmap_mask,gc,x_return, y_return, - b->icon->width,b->icon->height); - else - XCopyArea(Dpy,b->icon->mask,pmap_mask,gc,0,0, - b->icon->width,b->icon->height,x_return,y_return); - } - else - { - number=buttonNum(b); - XFillRectangle(Dpy,pmap_mask,gc,buttonXPos(b,number), - buttonYPos(b,number), - buttonWidth(b),buttonHeight(b)); - } + Pixmap pmap_mask; + button_info *b; + GC gc; + XGCValues gvals; + unsigned long gcm = 0; + Window root_return; + int x_return, y_return; + unsigned int width_return, height_return; + unsigned int border_width_return; + unsigned int depth_return; + int number, i; + XFontStruct *font; + + pmap_mask = XCreatePixmap(Dpy, MyWindow, w, h, 1); + gc = XCreateGC(Dpy, pmap_mask, (unsigned long)0, &gvals); + XSetForeground(Dpy, gc, 0); + XFillRectangle(Dpy, pmap_mask, gc, 0, 0, w, h); + XSetForeground(Dpy, gc, 1); + + /* + * if button has an icon, draw a rect with the same size as the icon + * (or the mask of the icon), + * else draw a rect with the same size as the button. + */ + + i = -1; + while (NextButton(&ub, &b, &i, 0)) { + if (b->flags & b_Icon) { + XGetGeometry(Dpy, b->IconWin, &root_return, &x_return, + &y_return, &width_return, &height_return, + &border_width_return, &depth_return); + + number = buttonNum(b); + if (b->icon->mask == None) + XFillRectangle(Dpy, pmap_mask, gc, x_return, + y_return, b->icon->width, b->icon->height); + else + XCopyArea(Dpy, b->icon->mask, pmap_mask, gc, 0, + 0, b->icon->width, b->icon->height, + x_return, y_return); + } else { + number = buttonNum(b); + XFillRectangle(Dpy, pmap_mask, gc, + buttonXPos(b, number), buttonYPos(b, number), + buttonWidth(b), buttonHeight(b)); + } - /* handle button's title */ - font=buttonFont(b); - if(b->flags&b_Title && font) - { - gcm = GCForeground | GCFont; - gvals.foreground=1; - gvals.font = font->fid; - XChangeGC(Dpy,gc,gcm,&gvals); - DrawTitle(b,pmap_mask,gc); + /* handle button's title */ + font = buttonFont(b); + if (b->flags & b_Title && font) { + gcm = GCForeground | GCFont; + gvals.foreground = 1; + gvals.font = font->fid; + XChangeGC(Dpy, gc, gcm, &gvals); + DrawTitle(b, pmap_mask, gc); + } } - } - XFreeGC(Dpy,gc); - XShapeCombineMask(Dpy,MyWindow,ShapeBounding,0,0,pmap_mask,ShapeSet); + XFreeGC(Dpy, gc); + XShapeCombineMask( + Dpy, MyWindow, ShapeBounding, 0, 0, pmap_mask, ShapeSet); } #endif @@ -458,12 +452,21 @@ void SetTransparentBackground(button_info *ub,int w,int h) *** myErrorHandler() *** Shows X errors made by FvwmButtons. **/ -XErrorHandler oldErrorHandler=NULL; -int myErrorHandler(Display *dpy, XErrorEvent *event) +XErrorHandler oldErrorHandler = NULL; +int +myErrorHandler(Display *dpy, XErrorEvent *event) { - fprintf(stderr,"%s: Cause of next X Error.\n",MyName); - /* return (*oldErrorHandler)(dpy,event); */ - return 0; + fprintf(stderr, "%s: Cause of next X Error.\n", MyName); + /* return (*oldErrorHandler)(dpy,event); */ + return 0; +} + +static int +IOErrorHandler(Display *dpy) +{ + (void)dpy; + connection_dead = True; + _exit(1); } /* ---------------------------------- main ----------------------------------*/ @@ -471,217 +474,227 @@ int myErrorHandler(Display *dpy, XErrorEvent *event) /** *** main() **/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *display_name = NULL; - int i; - Window root; - int x,y,maxx,maxy,border_width,depth; - char *temp, *s; - button_info *b,*ub; - - temp=argv[0]; - s=strrchr(argv[0],'/'); - if(s) temp=s+1; - MyName=mymalloc(strlen(temp)+1); - strcpy(MyName,temp); + char *display_name = NULL; + int i; + Window root; + int x, y, maxx, maxy, border_width, depth; + char *temp, *s; + button_info *b, *ub; + + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s) + temp = s + 1; + { + size_t name_len = strlen(temp) + 1; + MyName = xmalloc((int)name_len); + strlcpy(MyName, temp, name_len); + } #ifdef HAVE_SIGACTION - { - struct sigaction sigact; - - sigemptyset(&sigact.sa_mask); -# ifdef SA_INTERRUPT - sigact.sa_flags = SA_INTERRUPT; -# else - sigact.sa_flags = 0; -# endif - sigact.sa_handler = TerminateHandler; - - sigaction(SIGPIPE, &sigact, NULL); - sigaction(SIGINT, &sigact, NULL); - sigaction(SIGHUP, &sigact, NULL); - sigaction(SIGQUIT, &sigact, NULL); - sigaction(SIGTERM, &sigact, NULL); - } + { + struct sigaction sigact; + + sigemptyset(&sigact.sa_mask); +#ifdef SA_INTERRUPT + sigact.sa_flags = SA_INTERRUPT; #else - /* We don't have sigaction(), so fall back to less robust methods. */ - signal(SIGPIPE, TerminateHandler); - signal(SIGINT, TerminateHandler); - signal(SIGHUP, TerminateHandler); - signal(SIGQUIT, TerminateHandler); - signal(SIGTERM, TerminateHandler); + sigact.sa_flags = 0; #endif + sigact.sa_handler = TerminateHandler; + + sigaction(SIGPIPE, &sigact, NULL); + sigaction(SIGINT, &sigact, NULL); + sigaction(SIGHUP, &sigact, NULL); + sigaction(SIGQUIT, &sigact, NULL); + sigaction(SIGTERM, &sigact, NULL); + } +#else + /* We don't have sigaction(), so fall back to less robust methods. */ + signal(SIGPIPE, TerminateHandler); + signal(SIGINT, TerminateHandler); + signal(SIGHUP, TerminateHandler); + signal(SIGQUIT, TerminateHandler); + signal(SIGTERM, TerminateHandler); +#endif + + if (argc < 6 || argc > 8) { + fprintf(stderr, "%s v%s should only be executed by fvwm!\n", + MyName, VERSION); + exit(1); + } + + if (argc > 6) { /* There is a naming argument here! */ + free(MyName); + MyName = strdup(argv[6]); + } + + if (argc > 7) { /* There is a config file here! */ + config_file = strdup(argv[7]); + } + + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + if (!(Dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: Can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + XSetIOErrorHandler(IOErrorHandler); + x_fd = XConnectionNumber(Dpy); + fd_width = GetFdWidth(); + + screen = DefaultScreen(Dpy); + Root = RootWindow(Dpy, screen); + if (Root == None) { + fprintf(stderr, "%s: Screen %d is not valid\n", MyName, screen); + exit(1); + } + d_depth = DefaultDepth(Dpy, screen); + + oldErrorHandler = XSetErrorHandler(myErrorHandler); + + UberButton = (button_info *)xmalloc(sizeof(button_info)); + memset(UberButton, 0, sizeof(button_info)); + UberButton->flags = 0; + UberButton->parent = NULL; + UberButton->BWidth = 1; + UberButton->BHeight = 1; + UberButton->font = NULL; + UberButton->font_string = NULL; + UberButton->x = -30000; + UberButton->y = -30000; + MakeContainer(UberButton); + + dpw = DisplayWidth(Dpy, screen); + dph = DisplayHeight(Dpy, screen); + +#ifdef DEBUG_INIT + fprintf(stderr, "%s: Parsing...", MyName); +#endif + + CurrentPanel = MainPanel = (panel_info *)xmalloc(sizeof(panel_info)); + memset(MainPanel, 0, sizeof(panel_info)); + MainPanel->next = NULL; + MainPanel->uber = UberButton; + MainPanel->geom_w = -1; + MainPanel->geom_h = -1; + UberButton->title = MyName; + UberButton->swallow = 1; /* the panel is shown */ + + ParseOptions(UberButton); + + CurrentPanel = MainPanel; /* reassign CurrentPanel */ + while (CurrentPanel) { + UberButton = CurrentPanel->uber; + + if (UberButton->c->num_buttons == 0) { + fprintf(stderr, "%s: No buttons defined. Quitting\n", + MyName); + exit(0); + } + +#ifdef DEBUG_INIT + fprintf(stderr, "OK\n%s: Shuffling...", MyName); +#endif + + ShuffleButtons(UberButton); + NumberButtons(UberButton); + +#ifdef DEBUG_INIT + fprintf(stderr, "OK\n%s: Loading data...\n", MyName); +#endif + + /* Load fonts and icons, calculate max buttonsize */ + maxx = 0; + maxy = 0; + InitPictureCMap(Dpy, Root); /* store the root cmap */ + RecursiveLoadData(UberButton, &maxx, &maxy); + +#ifdef DEBUG_INIT + fprintf(stderr, "%s: Creating main window...", MyName); +#endif + + CreateWindow(UberButton, maxx, maxy); + + CurrentPanel->uber->IconWinParent = MyWindow; + CurrentPanel->uber->icon_w = maxx; + CurrentPanel->uber->icon_h = maxy; + +#ifdef DEBUG_INIT + fprintf(stderr, "OK\n%s: Creating icon windows...", MyName); +#endif + + i = -1; + ub = UberButton; + while (NextButton(&ub, &b, &i, 0)) + if (b->flags & b_Icon) { +#ifdef DEBUG_INIT + fprintf(stderr, "0x%06x...", (ushort)b); +#endif + CreateIconWindow(b); + } + +#ifdef DEBUG_INIT + fprintf(stderr, "OK\n%s: Configuring windows...", MyName); +#endif + + XGetGeometry(Dpy, MyWindow, &root, &x, &y, (ushort *)&Width, + (ushort *)&Height, (ushort *)&border_width, + (ushort *)&depth); + SetButtonSize(UberButton, Width, Height); + i = -1; + ub = UberButton; + while (NextButton(&ub, &b, &i, 0)) + ConfigureIconWindow(b); + +#ifdef SHAPE + if (UberButton->c->flags & b_TransBack) + SetTransparentBackground(UberButton, Width, Height); +#endif + + i = -1; + ub = UberButton; + while (NextButton(&ub, &b, &i, 0)) + MakeButton(b); + + CurrentPanel = CurrentPanel->next; + } + CurrentPanel = MainPanel; + UberButton = CurrentPanel->uber; + MyWindow = UberButton->IconWinParent; + +#ifdef DEBUG_INIT + fprintf(stderr, "OK\n%s: Mapping windows...", MyName); +#endif + + XMapSubwindows(Dpy, MyWindow); + XMapWindow(Dpy, MyWindow); + + SetMessageMask(fd, M_NEW_DESK | M_END_WINDOWLIST | M_MAP | + M_WINDOW_NAME | M_RES_CLASS | M_CONFIG_INFO | + M_END_CONFIG_INFO | M_RES_NAME); + + /* request a window list, since this triggers a response which + * will tell us the current desktop and paging status, needed to + * indent buttons correctly */ + MySendText(fd, "Send_WindowList", 0); - if(argc<6 || argc>8) - { - fprintf(stderr,"%s v%s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - if(argc>6) /* There is a naming argument here! */ - { - free(MyName); - MyName=strdup(argv[6]); - } - - if(argc>7) /* There is a config file here! */ - { - config_file=strdup(argv[7]); - } - - fd[0]=atoi(argv[1]); - fd[1]=atoi(argv[2]); - if (!(Dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: Can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - x_fd=XConnectionNumber(Dpy); - fd_width=GetFdWidth(); - - screen=DefaultScreen(Dpy); - Root=RootWindow(Dpy, screen); - if(Root==None) - { - fprintf(stderr,"%s: Screen %d is not valid\n",MyName,screen); - exit(1); - } - d_depth = DefaultDepth(Dpy, screen); - - oldErrorHandler=XSetErrorHandler(myErrorHandler); - - UberButton=(button_info*)mymalloc(sizeof(button_info)); - memset(UberButton, 0, sizeof(button_info)); - UberButton->flags=0; - UberButton->parent=NULL; - UberButton->BWidth=1; - UberButton->BHeight=1; - UberButton->font = NULL; - UberButton->font_string = NULL; - MakeContainer(UberButton); - - dpw = DisplayWidth(Dpy,screen); - dph = DisplayHeight(Dpy,screen); - -# ifdef DEBUG_INIT - fprintf(stderr,"%s: Parsing...",MyName); -# endif - - CurrentPanel = MainPanel - = (panel_info *) mymalloc(sizeof(panel_info)); - MainPanel->next = NULL; - MainPanel->uber = UberButton; - UberButton->title = MyName; - UberButton->swallow = 1; /* the panel is shown */ - - ParseOptions(UberButton); - - CurrentPanel = MainPanel; /* reassign CurrentPanel */ - while (CurrentPanel) - { UberButton = CurrentPanel->uber; - - if(UberButton->c->num_buttons==0) - { - fprintf(stderr,"%s: No buttons defined. Quitting\n", MyName); - exit(0); - } - -# ifdef DEBUG_INIT - fprintf(stderr,"OK\n%s: Shuffling...",MyName); -# endif - - ShuffleButtons(UberButton); - NumberButtons(UberButton); - -# ifdef DEBUG_INIT - fprintf(stderr,"OK\n%s: Loading data...\n",MyName); -# endif - - /* Load fonts and icons, calculate max buttonsize */ - maxx=0;maxy=0; - InitPictureCMap(Dpy,Root); /* store the root cmap */ - RecursiveLoadData(UberButton,&maxx,&maxy); - -# ifdef DEBUG_INIT - fprintf(stderr,"%s: Creating main window...",MyName); -# endif - - CreateWindow(UberButton,maxx,maxy); - - CurrentPanel->uber->IconWinParent = MyWindow; - CurrentPanel->uber->icon_w = maxx; - CurrentPanel->uber->icon_h = maxy; - -# ifdef DEBUG_INIT - fprintf(stderr,"OK\n%s: Creating icon windows...",MyName); -# endif - - i=-1;ub=UberButton; - while(NextButton(&ub,&b,&i,0)) - if(b->flags&b_Icon) - { #ifdef DEBUG_INIT - fprintf(stderr,"0x%06x...",(ushort)b); + fprintf(stderr, "OK\n%s: Startup complete\n", MyName); #endif - CreateIconWindow(b); - } - -# ifdef DEBUG_INIT - fprintf(stderr,"OK\n%s: Configuring windows...",MyName); -# endif - - XGetGeometry(Dpy,MyWindow,&root,&x,&y,(ushort*)&Width,(ushort*)&Height, - (ushort*)&border_width,(ushort*)&depth); - SetButtonSize(UberButton,Width,Height); - i=-1;ub=UberButton; - while(NextButton(&ub,&b,&i,0)) - ConfigureIconWindow(b); - -# ifdef SHAPE - if(UberButton->c->flags&b_TransBack) - SetTransparentBackground(UberButton,Width,Height); -# endif - - i=-1;ub=UberButton; - while(NextButton(&ub,&b,&i,0)) - MakeButton(b); - - CurrentPanel = CurrentPanel->next; - } - CurrentPanel = MainPanel; - UberButton = CurrentPanel->uber; - MyWindow = UberButton->IconWinParent; - -# ifdef DEBUG_INIT - fprintf(stderr,"OK\n%s: Mapping windows...",MyName); -# endif - - XMapSubwindows(Dpy,MyWindow); - XMapWindow(Dpy,MyWindow); - - SetMessageMask(fd, M_NEW_DESK | M_END_WINDOWLIST | M_MAP | M_WINDOW_NAME | - M_RES_CLASS | M_CONFIG_INFO | M_END_CONFIG_INFO | M_RES_NAME); - - /* request a window list, since this triggers a response which - * will tell us the current desktop and paging status, needed to - * indent buttons correctly */ - MySendText(fd,"Send_WindowList",0); - -# ifdef DEBUG_INIT - fprintf(stderr,"OK\n%s: Startup complete\n",MyName); -# endif - - /* - ** Now that we have finished initialising everything, - ** it is safe(r) to install the clean-up handlers ... - */ - atexit(DeadPipeCleanup); - Loop(); - - return 0; + + /* + ** Now that we have finished initialising everything, + ** it is safe(r) to install the clean-up handlers ... + */ + atexit(DeadPipeCleanup); + Loop(); + + return 0; } /* -------------------------------- Main Loop -------------------------------*/ @@ -689,308 +702,427 @@ int main(int argc, char **argv) /** *** Loop **/ -void Loop(void) +void +Loop(void) { - XEvent Event; - KeySym keysym; - char buffer[10],*tmp,*act; - int i,i2,button; - button_info *ub,*b; - panel_info *ppi; + XEvent Event; + KeySym keysym; + char buffer[10], *tmp, *act; + int i, i2, button; + button_info *ub, *b; + panel_info *ppi; #ifndef OLD_EXPOSE - int ex=10000,ey=10000,ex2=0,ey2=0; + int ex = 10000, ey = 10000, ex2 = 0, ey2 = 0; #endif - while( !isTerminated ) - { - if(My_XNextEvent(Dpy,&Event)) - { - switch(Event.type) - { - case Expose: - PanelIndex = MainPanel; - while (PanelIndex && (PanelIndex->uber->IconWinParent != Event.xany.window)) - PanelIndex = PanelIndex->next; - if (PanelIndex) - { UberButton = PanelIndex->uber; - MyWindow = UberButton->IconWinParent; - } - else - break; + sandbox_x11_config("FvwmButtons"); + sandbox_x11_config("FvwmButtons"); + + while (!isTerminated) { + if (My_XNextEvent(Dpy, &Event)) { + switch (Event.type) { + case Expose: + PanelIndex = MainPanel; + while (PanelIndex && + (PanelIndex->uber->IconWinParent != + Event.xany.window)) + PanelIndex = PanelIndex->next; + if (PanelIndex) { + UberButton = PanelIndex->uber; + MyWindow = UberButton->IconWinParent; + } else + break; #ifdef OLD_EXPOSE - if(Event.xexpose.count == 0) - { - button=-1;ub=UberButton; - while(NextButton(&ub,&b,&button,1)) - { - if(!ready && !(b->flags&b_Container)) - MakeButton(b); - RedrawButton(b,1); - } - if(!ready) - ready++; - } + if (Event.xexpose.count == 0) { + button = -1; + ub = UberButton; + while (NextButton(&ub, &b, &button, + 1)) { + if (!ready && + !(b->flags & b_Container)) + MakeButton(b); + RedrawButton(b, 1); + } + if (!ready) + ready++; + } #else - ex=min(ex,Event.xexpose.x); - ey=min(ey,Event.xexpose.y); - ex2=max(ex2,Event.xexpose.x+Event.xexpose.width); - ey2=max(ey2,Event.xexpose.y+Event.xexpose.height); - - if(Event.xexpose.count==0) - { - button=-1;ub=UberButton; - while(NextButton(&ub,&b,&button,1)) - { - if(b->flags&b_Container) - { - x=buttonXPos(b,buttonNum(b)); - y=buttonYPos(b,buttonNum(b)); - } - else - { - x=buttonXPos(b,button); - y=buttonYPos(b,button); - } - if(!(ex > x + buttonWidth(b) || ex2 < x || - ey > y + buttonHeight(b) || ey2 < y)) - { - if(ready<1 && !(b->flags&b_Container)) - MakeButton(b); - RedrawButton(b,1); - } - } - if(ready<1) - ready++; - - ex=ey=10000;ex2=ey2=0; - } + ex = min(ex, Event.xexpose.x); + ey = min(ey, Event.xexpose.y); + ex2 = max( + ex2, Event.xexpose.x + Event.xexpose.width); + ey2 = max(ey2, + Event.xexpose.y + Event.xexpose.height); + + if (Event.xexpose.count == 0) { + button = -1; + ub = UberButton; + while (NextButton(&ub, &b, &button, + 1)) { + if (b->flags & b_Container) { + x = buttonXPos( + b, buttonNum(b)); + y = buttonYPos( + b, buttonNum(b)); + } else { + x = buttonXPos( + b, button); + y = buttonYPos( + b, button); + } + if (!(ex > x + buttonWidth(b) || + ex2 < x || + ey > y + buttonHeight( + b) || + ey2 < y)) { + if (ready < 1 && + !(b->flags & + b_Container)) + MakeButton(b); + RedrawButton(b, 1); + } + } + if (ready < 1) + ready++; + + ex = ey = 10000; + ex2 = ey2 = 0; + } #endif - break; - - case ConfigureNotify: - /* XGetGeometry(Dpy, MyWindow, &root, &x, &y, - (ushort*)&tw,(ushort*)&th, - (ushort*)&border_width,(ushort*)&depth); - if(tw!=Width || th!=Height) - { - Width=tw; - Height=th; - SetButtonSize(UberButton,Width,Height); - button=-1;ub=UberButton; - while(NextButton(&ub,&b,&button,0)) - MakeButton(b); - RedrawWindow(NULL); - } */ /* I don't like to change its size after it started */ - break; - - case KeyPress: - XLookupString(&Event.xkey,buffer,10,&keysym,0); - if(keysym!=XK_Return && keysym!=XK_KP_Enter && keysym!=XK_Linefeed) - break; /* fall through to ButtonPress */ - case ButtonPress: - PanelIndex = MainPanel; - b = NULL; - do - if (PanelIndex->uber->swallow) /* is the panel shown? */ - { - UberButton = PanelIndex->uber; - MyWindow = UberButton->IconWinParent; - if (Event.xany.window == MyWindow) - CurrentButton = b = - select_button(UberButton,Event.xbutton.x,Event.xbutton.y); - } - while (!b && PanelIndex->next && (PanelIndex = PanelIndex->next)) - ; - - if(!b || !(b->flags&b_Action) || - ((act=GetButtonAction(b,Event.xbutton.button)) == NULL && - (act=GetButtonAction(b,0)) == NULL)) - { - CurrentButton=NULL; - break; - } - - /* record the panel, the button pressed */ - CurrentPanel = PanelIndex; - UberButton = CurrentPanel->uber; - MyWindow = UberButton->IconWinParent; - - RedrawButton(b,0); - if(strncasecmp(act,"popup",5)!=0) - { - if (strncasecmp(act, "panel-", 6) == 0) - Slide(seekpanel(b), b); - break; - } - else /* i.e. action is Popup */ - XUngrabPointer(Dpy,CurrentTime); /* And fall through */ - - case KeyRelease: - case ButtonRelease: - PanelIndex = MainPanel; - b = NULL; - do - { if (PanelIndex->uber->swallow) - { - UberButton = PanelIndex->uber; - MyWindow = UberButton->IconWinParent; - if (Event.xany.window == MyWindow) - b=select_button(UberButton,Event.xbutton.x,Event.xbutton.y); - } - } while (!b && (PanelIndex = PanelIndex->next)); - - if(!(act=GetButtonAction(b,Event.xbutton.button))) - act=GetButtonAction(b,0); - if(b && b==CurrentButton && act) - { - if(strncasecmp(act,"Exec",4)==0) - { - /* close current subpanel */ - if (PanelIndex != MainPanel) - Slide(PanelIndex, NULL); - - /* Look for Exec "identifier", in which case the button - stays down until window "identifier" materializes */ - i=4; - while(act[i]!=0 && act[i]!='"' && - isspace(act[i])) - i++; - if(act[i] == '"') - { - i2=i+1; - while(act[i2]!=0 && act[i2]!='"') - i2++; - - if(i2-i>1) - { - b->flags|=b_Hangon; - b->hangon = mymalloc(i2-i); - strncpy(b->hangon,&act[i+1],i2-i-1); - b->hangon[i2-i-1] = 0; - } - i2++; - } - else - i2=i; - - tmp=mymalloc(strlen(act)+1); - strcpy(tmp,"Exec "); - while(act[i2]!=0 && isspace(act[i2])) - i2++; - strcat(tmp,&act[i2]); - MySendText(fd,tmp,0); - free(tmp); - } - else if(strncasecmp(act,"DumpButtons",11)==0) - DumpButtons(UberButton); - else if(strncasecmp(act,"SaveButtons",11)==0) - SaveButtons(UberButton); - else if(strncasecmp(act,"panel",5)) - MySendText(fd,act,0); - } - - /* recover the old record */ - UberButton = CurrentPanel->uber; /* the panel, the button pressed */ - MyWindow = UberButton->IconWinParent; - - b=CurrentButton; - CurrentButton=NULL; - if(b) - RedrawButton(b,0); - break; - - case ClientMessage: - if(Event.xclient.format==32 && - Event.xclient.data.l[0]==_XA_WM_DEL_WIN) - { - for (ppi = MainPanel->next; ppi != NULL; - ppi = ppi->next) - { - if (ppi->uber->IconWinParent == Event.xany.window) - { - /* Only close the panel */ - Slide(ppi, NULL); - break; - } - } - if (ppi == NULL) - DeadPipe(1); - } - break; - - case PropertyNotify: - if(Event.xany.window==None) - break; - ub=UberButton;button=-1; - while(NextButton(&ub,&b,&button,0)) - if((buttonSwallowCount(b)==3) && Event.xany.window==b->IconWin) - { - if(Event.xproperty.atom==XA_WM_NAME && - buttonSwallow(b)&b_UseTitle) - { - if(b->flags&b_Title) - free(b->title); - b->flags|=b_Title; - XFetchName(Dpy,b->IconWin,&tmp); - CopyString(&b->title,tmp); - XFree(tmp); - MakeButton(b); - } - else if((Event.xproperty.atom==XA_WM_NORMAL_HINTS) && - (!(buttonSwallow(b)&b_NoHints))) - { - long supp; - if(!XGetWMNormalHints(Dpy,b->IconWin,b->hints,&supp)) - b->hints->flags = 0; - MakeButton(b); - } - RedrawButton(b,1); - } - break; - - /* Not really sure if this is abandon all hope.. */ - /* case UnmapNotify: */ - case DestroyNotify: - ub=UberButton;button=-1; - while(NextButton(&ub,&b,&button,0)) - if((buttonSwallowCount(b)==3) && Event.xany.window==b->IconWin) - { -# ifdef DEBUG_HANGON - fprintf(stderr, - "%s: Button 0x%06x lost its window 0x%x (\"%s\")", - MyName,(ushort)b,(ushort)b->IconWin,b->hangon); -# endif - b->swallow&=~b_Count; - b->IconWin=None; - if(buttonSwallow(b)&b_Respawn && b->hangon && b->spawn) - { -# ifdef DEBUG_HANGON - fprintf(stderr,", respawning\n"); -# endif - b->swallow|=1; - b->flags|=b_Swallow|b_Hangon; - MySendText(fd,b->spawn,0); - } - else - { - b->flags&=~b_Swallow; -# ifdef DEBUG_HANGON - fprintf(stderr,"\n"); -# endif - } - break; + break; + + case ConfigureNotify: + /* XGetGeometry(Dpy, MyWindow, &root, &x, &y, + (ushort*)&tw,(ushort*)&th, + (ushort*)&border_width,(ushort*)&depth); + if(tw!=Width || th!=Height) + { + Width=tw; + Height=th; + SetButtonSize(UberButton,Width,Height); + button=-1;ub=UberButton; + while(NextButton(&ub,&b,&button,0)) + MakeButton(b); + RedrawWindow(NULL); + } */ +/* I don't like to change its size after it started */ + break; + + case KeyPress: + XLookupString( + &Event.xkey, buffer, 10, &keysym, 0); + if (keysym != XK_Return && + keysym != XK_KP_Enter && + keysym != XK_Linefeed) + break; /* fall through to ButtonPress */ + case ButtonPress: { + button_info *ub2, *b2; + int b2num = -1; + + ub2 = UberButton; + while (NextButton(&ub2, &b2, &b2num, 0)) + if ((buttonSwallowCount(b2) == 3) && + Event.xany.window == b2->IconWin) { + b = b2; + CurrentButton = b; + break; + } + } + if (!b) { + PanelIndex = MainPanel; + b = NULL; + do + if (PanelIndex->uber + ->swallow) { /* is the panel + shown? */ + UberButton = PanelIndex->uber; + MyWindow = + UberButton->IconWinParent; + if (Event.xany.window == + MyWindow) + CurrentButton = b = + select_button( + UberButton, + Event.xbutton.x, + Event.xbutton + .y); + } + while (!b && PanelIndex->next && + (PanelIndex = PanelIndex->next)); + } else { + button_info *btn; + + btn = b; + PanelIndex = MainPanel; + while (PanelIndex && + PanelIndex->uber != + btn->uber) + PanelIndex = + PanelIndex->next; + UberButton = CurrentPanel ? + CurrentPanel->uber : + PanelIndex ? PanelIndex->uber : + UberButton; + MyWindow = UberButton->IconWinParent; + } + + if (!b || !(b->flags & b_Action) || + ((act = GetButtonAction( + b, Event.xbutton.button)) == NULL && + (act = GetButtonAction(b, 0)) == + NULL)) { + CurrentButton = NULL; + break; + } + + /* record the panel, the button pressed */ + CurrentPanel = PanelIndex; + UberButton = CurrentPanel->uber; + MyWindow = UberButton->IconWinParent; + + RedrawButton(b, 0); + if (strncasecmp(act, "popup", 5) != 0) { + if (strncasecmp(act, "panel-", 6) == 0) + Slide(seekpanel(b), b); + break; + } else /* i.e. action is Popup */ + XUngrabPointer(Dpy, + CurrentTime); /* And fall through */ + + case KeyRelease: + case ButtonRelease: + PanelIndex = MainPanel; + b = NULL; + do { + if (PanelIndex->uber->swallow) { + UberButton = PanelIndex->uber; + MyWindow = + UberButton->IconWinParent; + if (Event.xany.window == + MyWindow) + b = select_button( + UberButton, + Event.xbutton.x, + Event.xbutton.y); + } + } while (!b && (PanelIndex = PanelIndex->next)); + + if (!(act = GetButtonAction( + b, Event.xbutton.button))) + act = GetButtonAction(b, 0); + if (b && b == CurrentButton && act) { + if (strncasecmp(act, "Exec", 4) == 0) { + /* close current subpanel */ + if (PanelIndex != MainPanel) + Slide(PanelIndex, NULL); + + /* Look for Exec "identifier", + in which case the button + stays down until + window "identifier" + materializes */ + i = 4; + while (act[i] != 0 && + act[i] != '"' && + isspace(act[i])) + i++; + if (act[i] == '"') { + i2 = i + 1; + while (act[i2] != 0 && + act[i2] != '"') + i2++; + + if (i2 - i > 1) { + b->flags |= + b_Hangon; + b->hangon = + xmalloc( + i2 - i); + strncpy( + b->hangon, + &act[i + 1], + i2 - i - 1); + b->hangon[i2 - + i - + 1] = + 0; + } + i2++; + } else + i2 = i; + + { + size_t tmp_len = + strlen(act) + 1; + tmp = xmalloc( + (int)tmp_len); + strlcpy(tmp, "Exec ", + tmp_len); + while (act[i2] != 0 && + isspace(act[i2])) + i2++; + strlcat(tmp, &act[i2], + tmp_len); + MySendText(fd, tmp, 0); + free(tmp); + } + } else if (strncasecmp(act, + "DumpButtons", 11) == 0) + DumpButtons(UberButton); + else if (strncasecmp(act, "SaveButtons", + 11) == 0) + SaveButtons(UberButton); + else if (strncasecmp(act, "panel", 5)) + MySendText(fd, act, 0); + } + + /* recover the old record */ + UberButton = + CurrentPanel->uber; /* the panel, the button + pressed */ + MyWindow = UberButton->IconWinParent; + + b = CurrentButton; + CurrentButton = NULL; + if (b) + RedrawButton(b, 0); + break; + + case ClientMessage: + if (Event.xclient.format == 32 && + Event.xclient.data.l[0] == _XA_WM_DEL_WIN) { + for (ppi = MainPanel->next; ppi != NULL; + ppi = ppi->next) { + if (ppi->uber->IconWinParent == + Event.xany.window) { + /* Only close the panel + */ + Slide(ppi, NULL); + break; + } + } + if (ppi == NULL) + DeadPipe(1); + } + break; + + case PropertyNotify: + if (Event.xany.window == None) + break; + ub = UberButton; + button = -1; + while (NextButton(&ub, &b, &button, 0)) + if ((buttonSwallowCount(b) == 3) && + Event.xany.window == b->IconWin) { + if (Event.xproperty.atom == + XA_WM_NAME && + buttonSwallow(b) & + b_UseTitle) { + if (b->flags & b_Title) + free(b->title); + b->flags |= b_Title; + XFetchName(Dpy, + b->IconWin, &tmp); + CopyString( + &b->title, tmp); + XFree(tmp); + MakeButton(b); + } else if ((Event.xproperty.atom == + XA_WM_NORMAL_HINTS) && + (!(buttonSwallow(b) & + b_NoHints))) { + long supp; + if (!XGetWMNormalHints( + Dpy, b->IconWin, + b->hints, + &supp)) + b->hints + ->flags = 0; + MakeButton(b); + } + RedrawButton(b, 1); + } + break; + + /* Not really sure if this is abandon all hope.. */ + /* case UnmapNotify: */ + case DestroyNotify: + ub = UberButton; + button = -1; + while (NextButton(&ub, &b, &button, 0)) + if ((buttonSwallowCount(b) == 3) && + Event.xany.window == b->IconWin) { +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x lost " + "its window 0x%x (\"%s\")", + MyName, (ushort)b, + (ushort)b->IconWin, + b->hangon); +#endif + b->swallow &= ~b_Count; + b->IconWin = None; + if (buttonSwallow(b) & + b_Respawn && + b->hangon && b->spawn) { +#ifdef DEBUG_HANGON + fprintf(stderr, + ", respawning\n"); +#endif + b->swallow |= 1; + b->flags |= b_Swallow | + b_Hangon; + MySendText( + fd, b->spawn, 0); + } else { + b->flags &= ~b_Swallow; +#ifdef DEBUG_HANGON + fprintf(stderr, "\n"); +#endif + } + break; + } + break; + + default: +#ifdef DEBUG_EVENTS + fprintf(stderr, + "%s: Event fell through unhandled\n", + MyName); +#endif + break; + } } - break; + } +} - default: -# ifdef DEBUG_EVENTS - fprintf(stderr,"%s: Event fell through unhandled\n",MyName); -# endif - break; - } - } - } +static void +DrainDestroyEvents(void) +{ + XEvent dummy; + int button; + button_info *ub, *b; + + while (XCheckTypedEvent(Dpy, DestroyNotify, &dummy)) { + ub = UberButton; + button = -1; + while (NextButton(&ub, &b, &button, 0)) + if ((buttonSwallowCount(b) == 3) && + dummy.xany.window == b->IconWin) { + b->swallow &= ~b_Count; + b->IconWin = None; + if (buttonSwallow(b) & b_Respawn && + b->hangon && b->spawn) { + b->swallow |= 1; + b->flags |= b_Swallow | b_Hangon; + MySendText(fd, b->spawn, 0); + } else { + b->flags &= ~b_Swallow; + } + break; + } + } } /** @@ -998,408 +1130,411 @@ void Loop(void) *** Draws the window by traversing the button tree, draws all if NULL is given, *** otherwise only the given button. **/ -void RedrawWindow(button_info *b) +void +RedrawWindow(button_info *b) { - int button; - XEvent dummy; - button_info *ub; + int button; + XEvent dummy; + button_info *ub; - if(ready<1) - return; + if (ready < 1) + return; - /* Flush expose events */ - while (XCheckTypedWindowEvent (Dpy, MyWindow, Expose, &dummy)); + /* Flush expose events */ + while (XCheckTypedWindowEvent(Dpy, MyWindow, Expose, &dummy)) + ; - if(b) - { - RedrawButton(b,0); - return; - } + if (b) { + RedrawButton(b, 0); + return; + } - button=-1;ub=UberButton; - while(NextButton(&ub,&b,&button,1)) - RedrawButton(b,1); + button = -1; + ub = UberButton; + while (NextButton(&ub, &b, &button, 1)) + RedrawButton(b, 1); } /** *** LoadIconFile() **/ -int LoadIconFile(char *s,FvwmPicture **p) +int +LoadIconFile(char *s, FvwmPicture **p) { - *p=CachePicture(Dpy,Root,iconPath,pixmapPath,s, save_color_limit); - if(*p) - return 1; - return 0; + *p = CachePicture(Dpy, Root, iconPath, pixmapPath, s, save_color_limit); + if (*p) + return 1; + return 0; } /** *** RecursiveLoadData() *** Loads colors, fonts and icons, and calculates buttonsizes **/ -void RecursiveLoadData(button_info *b,int *maxx,int *maxy) +void +RecursiveLoadData(button_info *b, int *maxx, int *maxy) { - int i,j,x=0,y=0; - XFontStruct *font; + int i, j, x = 0, y = 0; + XFontStruct *font; - if(!b) return; + if (!b) + return; #ifdef DEBUG_LOADDATA - fprintf(stderr,"%s: Loading: Button 0x%06x: colors",MyName,(ushort)b); + fprintf( + stderr, "%s: Loading: Button 0x%06x: colors", MyName, (ushort)b); #endif - /* Load colors */ - if(b->flags&b_Fore) - b->fc=GetColor(b->fore); - if(b->flags&b_Back) - { - if(b->flags&b_IconBack) - { - if(!LoadIconFile(b->back,&b->backicon)) - b->flags&=~b_Back; - } - else - { - b->bc=GetColor(b->back); - b->hc=GetHilite(b->bc); - b->sc=GetShadow(b->bc); - } - } - if(b->flags&b_Container) - { -# ifdef DEBUG_LOADDATA - fprintf(stderr,", colors2"); -# endif - if(b->c->flags&b_Fore) - b->c->fc=GetColor(b->c->fore); - if(b->c->flags&b_Back) - { - if(b->c->flags&b_IconBack && !(b->c->flags&b_TransBack)) - { - if(!LoadIconFile(b->c->back_file,&b->c->backicon)) - b->c->flags&=~b_IconBack; - } - - { - b->c->bc=GetColor(b->c->back); - b->c->hc=GetHilite(b->c->bc); - b->c->sc=GetShadow(b->c->bc); - } + /* Load colors */ + if (b->flags & b_Fore) + b->fc = GetColor(b->fore); + if (b->flags & b_Back) { + if (b->flags & b_IconBack) { + if (!LoadIconFile(b->back, &b->backicon)) + b->flags &= ~b_Back; + } else { + b->bc = GetColor(b->back); + b->hc = GetHilite(b->bc); + b->sc = GetShadow(b->bc); + } } - } - - /* Load the font */ - if(b->flags&b_Font) - { -# ifdef DEBUG_LOADDATA - fprintf(stderr,", font \"%s\"",b->font_string); -# endif - - fprintf(stderr, "b=0x%lx, font_string=%s\n", - (unsigned long)b, b? b->font_string : "(NULL)"); - if(strncasecmp(b->font_string,"none",4)==0) - b->font=NULL; - else if(!(b->font=XLoadQueryFont(Dpy,b->font_string))) - { - b->flags&=~b_Font; - fprintf(stderr,"%s: Couldn't load font %s\n",MyName, - b->font_string); + if (b->flags & b_Container) { +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", colors2"); +#endif + if (b->c->flags & b_Fore) + b->c->fc = GetColor(b->c->fore); + if (b->c->flags & b_Back) { + if (b->c->flags & b_IconBack && + !(b->c->flags & b_TransBack)) { + if (!LoadIconFile( + b->c->back_file, &b->c->backicon)) + b->c->flags &= ~b_IconBack; + } + + { + b->c->bc = GetColor(b->c->back); + b->c->hc = GetHilite(b->c->bc); + b->c->sc = GetShadow(b->c->bc); + } + } } - } - - if(b->flags&b_Container && b->c->flags&b_Font) - { -# ifdef DEBUG_LOADDATA - fprintf(stderr,", font2 \"%s\"",b->c->font_string); -# endif - if(strncasecmp(b->c->font_string,"none",4)==0) - b->c->font=NULL; - else if(!(b->c->font=XLoadQueryFont(Dpy,b->c->font_string))) - { - fprintf(stderr,"%s: Couldn't load font %s\n",MyName, - b->c->font_string); - if(b==UberButton) - { - if(!(b->c->font=XLoadQueryFont(Dpy,"fixed"))) - fprintf(stderr,"%s: Couldn't load font fixed\n",MyName); - } - else - b->c->flags&=~b_Font; + + /* Load the font */ + if (b->flags & b_Font) { +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", font \"%s\"", b->font_string); +#endif + +#ifdef DEBUG_LOADDATA + fprintf(stderr, "b=0x%lx, font_string=%s\n", (unsigned long)b, + b ? b->font_string : "(NULL)"); +#endif + if (strncasecmp(b->font_string, "none", 4) == 0) + b->font = NULL; + else if (!(b->font = XLoadQueryFont(Dpy, b->font_string))) { + b->flags &= ~b_Font; + fprintf(stderr, "%s: Couldn't load font %s\n", MyName, + b->font_string); + } } - } + if (b->flags & b_Container && b->c->flags & b_Font) { +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", font2 \"%s\"", b->c->font_string); +#endif + if (strncasecmp(b->c->font_string, "none", 4) == 0) + b->c->font = NULL; + else if (!(b->c->font = + XLoadQueryFont(Dpy, b->c->font_string))) { + fprintf(stderr, "%s: Couldn't load font %s\n", MyName, + b->c->font_string); + if (b == UberButton) { + if (!(b->c->font = + XLoadQueryFont(Dpy, "fixed"))) + fprintf(stderr, + "%s: Couldn't load font fixed\n", + MyName); + } else + b->c->flags &= ~b_Font; + } + } + /* Calculate subbutton sizes */ + if (b->flags & b_Container && b->c->num_buttons) { +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", entering container\n"); +#endif + for (i = 0; i < b->c->num_buttons; i++) + if (b->c->buttons[i]) + RecursiveLoadData(b->c->buttons[i], &x, &y); - /* Calculate subbutton sizes */ - if(b->flags&b_Container && b->c->num_buttons) - { -# ifdef DEBUG_LOADDATA - fprintf(stderr,", entering container\n"); -# endif - for(i=0;ic->num_buttons;i++) - if(b->c->buttons[i]) - RecursiveLoadData(b->c->buttons[i],&x,&y); + if (b->c->flags & b_Size) { + x = b->c->minx; + y = b->c->miny; + } +#ifdef DEBUG_LOADDATA + fprintf(stderr, "%s: Loading: Back to container 0x%06x", MyName, + (ushort)b); +#endif - if(b->c->flags&b_Size) - { - x=b->c->minx; - y=b->c->miny; - } -# ifdef DEBUG_LOADDATA - fprintf(stderr,"%s: Loading: Back to container 0x%06x",MyName,(ushort)b); -# endif - - b->c->ButtonWidth=x; - b->c->ButtonHeight=y; - x*=b->c->num_columns; - y*=b->c->num_rows; - } - - - - i=0;j=0; - - /* Load the icon */ - if(b->flags&b_Icon && LoadIconFile(b->icon_file,&b->icon)) - { -# ifdef DEBUG_LOADDATA - fprintf(stderr,", icon \"%s\"",b->icon_file); -# endif - i=b->icon->width; - j=b->icon->height; - } - else - b->flags&=~b_Icon; - - if(b->flags&b_Title && (font=buttonFont(b))) - { -# ifdef DEBUG_LOADDATA - fprintf(stderr,", title \"%s\"",b->title); -# endif - if(buttonJustify(b)&b_Horizontal) - { - i+=buttonXPad(b)+XTextWidth(font,b->title,strlen(b->title)); - j=max(j,font->ascent+font->descent); + b->c->ButtonWidth = x; + b->c->ButtonHeight = y; + x *= b->c->num_columns; + y *= b->c->num_rows; } - else - { - i=max(i,XTextWidth(font,b->title,strlen(b->title))); - j+=font->ascent+font->descent; + + i = 0; + j = 0; + + /* Load the icon */ + if (b->flags & b_Icon && LoadIconFile(b->icon_file, &b->icon)) { +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", icon \"%s\"", b->icon_file); +#endif + i = b->icon->width; + j = b->icon->height; + } else + b->flags &= ~b_Icon; + + if (b->flags & b_Title && (font = buttonFont(b))) { +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", title \"%s\"", b->title); +#endif + if (buttonJustify(b) & b_Horizontal) { + i += buttonXPad(b) + + XTextWidth(font, b->title, strlen(b->title)); + j = max(j, font->ascent + font->descent); + } else { + i = max( + i, XTextWidth(font, b->title, strlen(b->title))); + j += font->ascent + font->descent; + } } - } - x+=i; - y+=j; + x += i; + y += j; - if(b->flags&b_Size) - { - x=b->minx; - y=b->miny; - } + if (b->flags & b_Size) { + x = b->minx; + y = b->miny; + } - x+=2*(buttonFrame(b)+buttonXPad(b)); - y+=2*(buttonFrame(b)+buttonYPad(b)); + x += 2 * (buttonFrame(b) + buttonXPad(b)); + y += 2 * (buttonFrame(b) + buttonYPad(b)); - x/=b->BWidth; - y/=b->BHeight; + x /= b->BWidth; + y /= b->BHeight; - *maxx=max(x,*maxx); - *maxy=max(y,*maxy); -# ifdef DEBUG_LOADDATA - fprintf(stderr,", size %ux%u, done\n",x,y); -# endif + *maxx = max(x, *maxx); + *maxy = max(y, *maxy); +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", size %ux%u, done\n", x, y); +#endif } /** *** CreateWindow() *** Sizes and creates the window **/ -void CreateWindow(button_info *ub,int maxx,int maxy) +void +CreateWindow(button_info *ub, int maxx, int maxy) { - XSizeHints mysizehints; - XGCValues gcv; - unsigned long gcm; - XClassHint myclasshints; - - x = CurrentPanel->uber->x; /* Geometry x where to put the panel */ - y = CurrentPanel->uber->y; /* Geometry y where to put the panel */ - xneg = CurrentPanel->uber->w; - yneg = CurrentPanel->uber->h; - - if(maxx<16) - maxx=16; - if(maxy<16) - maxy=16; - -# ifdef DEBUG_INIT - fprintf(stderr,"making atoms..."); -# endif - - _XA_WM_DEL_WIN = XInternAtom(Dpy,"WM_DELETE_WINDOW",0); - -# ifdef DEBUG_INIT - fprintf(stderr,"sizing..."); -# endif - - mysizehints.flags = PWinGravity | PResizeInc | PBaseSize; - - mysizehints.base_width=mysizehints.base_height=0; - -/* This should never be executed anyway, let's remove it. - if(ub->flags&b_Frame) - { - mysizehints.base_width+=2*abs(ub->framew); - mysizehints.base_height+=2*abs(ub->framew); - } - if(ub->flags&b_Padding) - { - mysizehints.base_width+=2*ub->xpad; - mysizehints.base_height+=2*ub->ypad; - } -*/ - mysizehints.width=mysizehints.base_width+maxx; - mysizehints.height=mysizehints.base_height+maxy; - mysizehints.width_inc=ub->c->num_columns; - mysizehints.height_inc=ub->c->num_rows; - mysizehints.base_height+=ub->c->num_rows*2; - mysizehints.base_width+=ub->c->num_columns*2; - - if(w>-1) /* from geometry */ - { -# ifdef DEBUG_INIT - fprintf(stderr,"constraining (w=%i)...",w); -# endif - ConstrainSize(&mysizehints,&w,&h); - mysizehints.width = w; - mysizehints.height = h; - mysizehints.flags |= USSize; - } - -# ifdef DEBUG_INIT - fprintf(stderr,"gravity..."); -# endif - mysizehints.x=0; - mysizehints.y=0; - if(x > -30000) - { - if (xneg) - { - mysizehints.x = DisplayWidth(Dpy,screen) + x - mysizehints.width; - gravity = NorthEastGravity; + XSizeHints mysizehints; + XGCValues gcv; + unsigned long gcm; + XClassHint myclasshints; + int req_w = -1; + int req_h = -1; + + x = CurrentPanel->uber->x; /* Geometry x where to put the panel */ + y = CurrentPanel->uber->y; /* Geometry y where to put the panel */ + xneg = CurrentPanel->uber->w; + yneg = CurrentPanel->uber->h; + gravity = NorthWestGravity; + + if (CurrentPanel) { + req_w = CurrentPanel->geom_w; + req_h = CurrentPanel->geom_h; } - else - mysizehints.x = x; - if (yneg) + w = (req_w > -1) ? req_w : -1; + h = (req_h > -1) ? req_h : -1; + + if (maxx < 16) + maxx = 16; + if (maxy < 16) + maxy = 16; + +#ifdef DEBUG_INIT + fprintf(stderr, "making atoms..."); +#endif + + _XA_WM_DEL_WIN = XInternAtom(Dpy, "WM_DELETE_WINDOW", 0); + +#ifdef DEBUG_INIT + fprintf(stderr, "sizing..."); +#endif + + mysizehints.flags = PWinGravity | PResizeInc | PBaseSize; + + mysizehints.base_width = mysizehints.base_height = 0; + + /* This should never be executed anyway, let's remove it. + if(ub->flags&b_Frame) + { + mysizehints.base_width+=2*abs(ub->framew); + mysizehints.base_height+=2*abs(ub->framew); + } + if(ub->flags&b_Padding) + { + mysizehints.base_width+=2*ub->xpad; + mysizehints.base_height+=2*ub->ypad; + } + */ + mysizehints.width = mysizehints.base_width + maxx; + mysizehints.height = mysizehints.base_height + maxy; + mysizehints.width_inc = ub->c->num_columns; + mysizehints.height_inc = ub->c->num_rows; + mysizehints.base_height += ub->c->num_rows * 2; + mysizehints.base_width += ub->c->num_columns * 2; + + if (req_w > -1 || req_h > -1) { /* from geometry */ +#ifdef DEBUG_INIT + fprintf(stderr, "constraining (w=%i,h=%i)...", req_w, req_h); +#endif + { + int tmp_w = (req_w > -1) ? req_w : mysizehints.width; + int tmp_h = (req_h > -1) ? req_h : mysizehints.height; + ConstrainSize(&mysizehints, &tmp_w, &tmp_h); + if (req_w > -1) + w = tmp_w; + else + w = -1; + if (req_h > -1) + h = tmp_h; + else + h = -1; + mysizehints.width = tmp_w; + mysizehints.height = tmp_h; + } + mysizehints.flags |= USSize; + } else { + w = -1; + h = -1; + } + +#ifdef DEBUG_INIT + fprintf(stderr, "gravity..."); +#endif + mysizehints.x = 0; + mysizehints.y = 0; + if (x > -30000) { + if (xneg) { + mysizehints.x = + DisplayWidth(Dpy, screen) + x - mysizehints.width; + gravity = NorthEastGravity; + } else + mysizehints.x = x; + if (yneg) { + mysizehints.y = + DisplayHeight(Dpy, screen) + y - mysizehints.height; + gravity = SouthWestGravity; + } else + mysizehints.y = y; + if (xneg && yneg) + gravity = SouthEastGravity; + mysizehints.flags |= USPosition; + } + mysizehints.win_gravity = gravity; + +#ifdef DEBUG_INIT + fprintf(stderr, "colors..."); +#endif + if (d_depth < 2) { + back_pix = GetColor("white"); + fore_pix = GetColor("black"); + hilite_pix = back_pix; + shadow_pix = fore_pix; + } else { + back_pix = GetColor(ub->c->back); + fore_pix = GetColor(ub->c->fore); + hilite_pix = GetHilite(back_pix); + shadow_pix = GetShadow(back_pix); + } + +#ifdef DEBUG_INIT + if (mysizehints.flags & USPosition) + fprintf(stderr, "create(%i,%i,%u,%u,1,%u,%u)...", mysizehints.x, + mysizehints.y, mysizehints.width, mysizehints.height, + (ushort)fore_pix, (ushort)back_pix); + else + fprintf(stderr, "create(-,-,%u,%u,1,%u,%u)...", + mysizehints.width, mysizehints.height, (ushort)fore_pix, + (ushort)back_pix); +#endif + + MyWindow = XCreateSimpleWindow(Dpy, Root, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, 0, fore_pix, back_pix); + if (ub->c->flags & b_IconBack && !(ub->c->flags & b_TransBack)) + XSetWindowBackgroundPixmap( + Dpy, MyWindow, ub->c->backicon->picture); + +#ifdef DEBUG_INIT + fprintf(stderr, "properties..."); +#endif + XSetWMProtocols(Dpy, MyWindow, &_XA_WM_DEL_WIN, 1); + + if (CurrentPanel == MainPanel) { + myclasshints.res_name = strdup(MyName); + } else { + size_t total_len = strlen(MyName) + sizeof("Panel"); + myclasshints.res_name = (char *)xmalloc(total_len); + strlcpy(myclasshints.res_name, MyName, total_len); + strlcat(myclasshints.res_name, "Panel", total_len); + } + myclasshints.res_class = strdup( + (CurrentPanel == MainPanel) ? "FvwmButtons" : "FvwmButtonsPanel"); + { - mysizehints.y = DisplayHeight(Dpy,screen) + y - mysizehints.height; - gravity = SouthWestGravity; + XTextProperty mynametext; + char *list[] = {NULL, NULL}; + list[0] = (CurrentPanel == MainPanel) ? + MyName : + CurrentPanel->uber->title; + if (!XStringListToTextProperty(list, 1, &mynametext)) { + fprintf(stderr, "%s: Failed to convert name to XText\n", + MyName); + exit(1); + } + XSetWMProperties(Dpy, MyWindow, &mynametext, &mynametext, NULL, + 0, &mysizehints, NULL, &myclasshints); + XFree(mynametext.value); } - else - mysizehints.y = y; - if(xneg && yneg) - gravity = SouthEastGravity; - mysizehints.flags |= USPosition; - } - mysizehints.win_gravity = gravity; - -# ifdef DEBUG_INIT - fprintf(stderr,"colors..."); -# endif - if(d_depth < 2) - { - back_pix = GetColor("white"); - fore_pix = GetColor("black"); - hilite_pix = back_pix; - shadow_pix = fore_pix; - } - else - { - back_pix = GetColor(ub->c->back); - fore_pix = GetColor(ub->c->fore); - hilite_pix = GetHilite(back_pix); - shadow_pix = GetShadow(back_pix); - } - -# ifdef DEBUG_INIT - if(mysizehints.flags&USPosition) - fprintf(stderr,"create(%i,%i,%u,%u,1,%u,%u)...", - mysizehints.x,mysizehints.y, - mysizehints.width,mysizehints.height, - (ushort)fore_pix,(ushort)back_pix); - else - fprintf(stderr,"create(-,-,%u,%u,1,%u,%u)...", - mysizehints.width,mysizehints.height, - (ushort)fore_pix,(ushort)back_pix); -# endif - - MyWindow = XCreateSimpleWindow(Dpy,Root,mysizehints.x,mysizehints.y, - mysizehints.width,mysizehints.height, - 0,fore_pix,back_pix); - if(ub->c->flags&b_IconBack && !(ub->c->flags&b_TransBack)) - XSetWindowBackgroundPixmap(Dpy,MyWindow,ub->c->backicon->picture); - - -# ifdef DEBUG_INIT - fprintf(stderr,"properties..."); -# endif - XSetWMProtocols(Dpy,MyWindow,&_XA_WM_DEL_WIN,1); - -#if 0 - myclasshints.res_name=strdup((CurrentPanel == MainPanel) - ? MyName : CurrentPanel->uber->title); -#else - if (CurrentPanel == MainPanel) - { - myclasshints.res_name=strdup(MyName); - } - else - { - myclasshints.res_name=(char *)malloc(strlen(MyName)+6); - strcpy(myclasshints.res_name,MyName); - strcat(myclasshints.res_name,"Panel"); - } + + XSelectInput(Dpy, MyWindow, MW_EVENTS); + +#ifdef DEBUG_INIT + fprintf(stderr, "GC..."); #endif - myclasshints.res_class=strdup((CurrentPanel == MainPanel) - ? "FvwmButtons" : "FvwmButtonsPanel"); - - { - XTextProperty mynametext; - char *list[]={NULL,NULL}; - list[0]=(CurrentPanel == MainPanel) ? MyName : CurrentPanel->uber->title; - if(!XStringListToTextProperty(list,1,&mynametext)) - { - fprintf(stderr,"%s: Failed to convert name to XText\n",MyName); - exit(1); - } - XSetWMProperties(Dpy,MyWindow,&mynametext,&mynametext, - NULL,0,&mysizehints,NULL,&myclasshints); - XFree(mynametext.value); - } - - XSelectInput(Dpy,MyWindow,MW_EVENTS); - -# ifdef DEBUG_INIT - fprintf(stderr,"GC..."); -# endif - gcm = GCForeground|GCBackground; - gcv.foreground = fore_pix; - gcv.background = back_pix; - if(ub && ub->c && ub->c->font && ub->font) - { - gcv.font = ub->c->font->fid; - gcm |= GCFont; - } - NormalGC = XCreateGC(Dpy, Root, gcm, &gcv); - - free(myclasshints.res_class); - free(myclasshints.res_name); + gcm = GCForeground | GCBackground; + gcv.foreground = fore_pix; + gcv.background = back_pix; + if (ub && ub->c && ub->c->font && ub->font) { + gcv.font = ub->c->font->fid; + gcm |= GCFont; + } + NormalGC = XCreateGC(Dpy, Root, gcm, &gcv); + + free(myclasshints.res_class); + free(myclasshints.res_name); } /* ----------------------------- color functions --------------------------- */ #ifdef XPM -# define MyAllocColor(a,b,c) PleaseAllocColor(c) +#define MyAllocColor(a, b, c) PleaseAllocColor(c) #else -# define MyAllocColor(a,b,c) XAllocColor(a,b,c) +#define MyAllocColor(a, b, c) XAllocColor(a, b, c) #endif /** @@ -1408,27 +1543,31 @@ void CreateWindow(button_info *ub,int maxx,int maxy) *** space. **/ #ifdef XPM -int PleaseAllocColor(XColor *color) +int +PleaseAllocColor(XColor *color) { - char *xpm[] = {"1 1 1 1",NULL,"x"}; - XpmAttributes attr; - XImage *dummy1=None,*dummy2=None; - static char buf[20]; - - sprintf(buf,"x c #%04x%04x%04x",color->red,color->green,color->blue); - xpm[1]=buf; - attr.valuemask=XpmCloseness; - attr.closeness=40000; /* value used by fvwm and fvwmlib */ - - if(XpmCreateImageFromData(Dpy,xpm,&dummy1,&dummy2,&attr)!=XpmSuccess) - { - fprintf(stderr,"%s: Unable to get similar color\n",MyName); - exit(1); - } - color->pixel=XGetPixel(dummy1,0,0); - if(dummy1!=None)XDestroyImage(dummy1); - if(dummy2!=None)XDestroyImage(dummy2); - return 1; + char *xpm[] = {"1 1 1 1", NULL, "x"}; + XpmAttributes attr; + XImage *dummy1 = None, *dummy2 = None; + static char buf[20]; + + snprintf(buf, sizeof(buf), "x c #%04x%04x%04x", color->red, + color->green, color->blue); + xpm[1] = buf; + attr.valuemask = XpmCloseness; + attr.closeness = 40000; /* value used by fvwm and fvwmlib */ + + if (XpmCreateImageFromData(Dpy, xpm, &dummy1, &dummy2, &attr) != + XpmSuccess) { + fprintf(stderr, "%s: Unable to get similar color\n", MyName); + exit(1); + } + color->pixel = XGetPixel(dummy1, 0, 0); + if (dummy1 != None) + XDestroyImage(dummy1); + if (dummy2 != None) + XDestroyImage(dummy2); + return 1; } #endif @@ -1436,86 +1575,71 @@ int PleaseAllocColor(XColor *color) *** nocolor() *** Complain **/ -void nocolor(const char *a, const char *b) +void +nocolor(const char *a, const char *b) { - fprintf(stderr,"%s: Can't %s %s, quitting, sorry...\n", MyName, a,b); - exit(1); + fprintf(stderr, "%s: Can't %s %s, quitting, sorry...\n", MyName, a, b); + exit(1); } /** *** GetColor() *** Loads a single color **/ -Pixel GetColor(char *name) +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(Dpy,Root,&attributes); - color.pixel = 0; - if (!XParseColor (Dpy, attributes.colormap, name, &color)) - nocolor("parse",name); - else if(!MyAllocColor(Dpy,attributes.colormap,&color)) - nocolor("alloc",name); - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(Dpy, Root, &attributes); + color.pixel = 0; + if (!XParseColor(Dpy, attributes.colormap, name, &color)) + nocolor("parse", name); + else if (!MyAllocColor(Dpy, attributes.colormap, &color)) + nocolor("alloc", name); + return color.pixel; } - /* --------------------------------------------------------------------------*/ #ifdef DEBUG_EVENTS -void DebugEvents(XEvent *event) +void +DebugEvents(XEvent *event) { - char *event_names[]={NULL,NULL, - "KeyPress","KeyRelease","ButtonPress", - "ButtonRelease","MotionNotify","EnterNotify", - "LeaveNotify","FocusIn","FocusOut", - "KeymapNotify","Expose","GraphicsExpose", - "NoExpose","VisibilityNotify","CreateNotify", - "DestroyNotify","UnmapNotify","MapNotify", - "MapRequest","ReparentNotify","ConfigureNotify", - "ConfigureRequest","GravityNotify","ResizeRequest", - "CirculateNotify","CirculateRequest","PropertyNotify", - "SelectionClear","SelectionRequest","SelectionNotify", - "ColormapNotify","ClientMessage","MappingNotify"}; - fprintf(stderr,"%s: Received %s event from window 0x%x\n", - MyName,event_names[event->type],(ushort)event->xany.window); + char *event_names[] = {NULL, NULL, "KeyPress", "KeyRelease", + "ButtonPress", "ButtonRelease", "MotionNotify", "EnterNotify", + "LeaveNotify", "FocusIn", "FocusOut", "KeymapNotify", "Expose", + "GraphicsExpose", "NoExpose", "VisibilityNotify", "CreateNotify", + "DestroyNotify", "UnmapNotify", "MapNotify", "MapRequest", + "ReparentNotify", "ConfigureNotify", "ConfigureRequest", + "GravityNotify", "ResizeRequest", "CirculateNotify", + "CirculateRequest", "PropertyNotify", "SelectionClear", + "SelectionRequest", "SelectionNotify", "ColormapNotify", + "ClientMessage", "MappingNotify"}; + fprintf(stderr, "%s: Received %s event from window 0x%x\n", MyName, + event_names[event->type], (ushort)event->xany.window); } #endif #ifdef DEBUG_FVWM -void DebugFvwmEvents(unsigned long type) +void +DebugFvwmEvents(unsigned long type) { - char *events[]={ -"M_NEW_PAGE", -"M_NEW_DESK", -"M_ADD_WINDOW", -"M_RAISE_WINDOW", -"M_LOWER_WINDOW", -"M_CONFIGURE_WINDOW", -"M_FOCUS_CHANGE", -"M_DESTROY_WINDOW", -"M_ICONIFY", -"M_DEICONIFY", -"M_WINDOW_NAME", -"M_ICON_NAME", -"M_RES_CLASS", -"M_RES_NAME", -"M_END_WINDOWLIST", -"M_ICON_LOCATION", -"M_MAP", -"M_ERROR", -"M_CONFIG_INFO", -"M_END_CONFIG_INFO", -"M_ICON_FILE", -"M_DEFAULTICON",NULL}; - int i=0; - while(events[i]) - { - if(type&1< 0) - { - - if(FD_ISSET(x_fd, &in_fdset)) - { - if(XPending(Dpy)) - { - XNextEvent(Dpy,event); - miss_counter = 0; -# ifdef DEBUG_EVENTS - DebugEvents(event); -# endif - return 1; - } - else - miss_counter++; - if(miss_counter > 100) - DeadPipe(0); - } - - if(FD_ISSET(fd[1], &in_fdset)) - { - if((count = ReadFvwmPacket(fd[1], header, &body)) > 0) - { - process_message(header[1],body); - free(body); + fd_set in_fdset; + unsigned long header[HEADER_SIZE]; + int count; + static int miss_counter = 0; + unsigned long *body; + + if (XPending(Dpy)) { + XNextEvent(Dpy, event); +#ifdef DEBUG_EVENTS + DebugEvents(event); +#endif + return 1; } - } - } - return 0; + FD_ZERO(&in_fdset); + FD_SET(x_fd, &in_fdset); + FD_SET(fd[1], &in_fdset); + + if (select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL) > 0) { + if (FD_ISSET(x_fd, &in_fdset)) { + if (XPending(Dpy)) { + XNextEvent(Dpy, event); + miss_counter = 0; +#ifdef DEBUG_EVENTS + DebugEvents(event); +#endif + return 1; + } else + miss_counter++; + if (miss_counter > 100) + DeadPipe(0); + } + + if (FD_ISSET(fd[1], &in_fdset)) { + if ((count = ReadFvwmPacket(fd[1], header, &body)) > + 0) { + process_message(header[1], body); + free(body); + } + } + } + return 0; } /** @@ -1582,67 +1699,69 @@ int My_XNextEvent(Display *Dpy, XEvent *event) *** Is run after the windowlist is checked. If any button hangs on UseOld, *** it has failed, so we try to spawn a window for them. **/ -void SpawnSome() +void +SpawnSome() { - static char first=1; - button_info *b,*ub=UberButton; - int button=-1; - if(!first) - return; - first=0; - while(NextButton(&ub,&b,&button,0)) - if((buttonSwallowCount(b)==1) && b->flags&b_Hangon && - buttonSwallow(b)&b_UseOld) - if(b->spawn) - { -# ifdef DEBUG_HANGON - fprintf(stderr,"%s: Button 0x%06x did not find a \"%s\" window, %s", - MyName,(ushort)b,b->hangon,"spawning own\n"); -# endif - SendText(fd,b->spawn,0); - } + static char first = 1; + button_info *b, *ub = UberButton; + int button = -1; + if (!first) + return; + first = 0; + while (NextButton(&ub, &b, &button, 0)) + if ((buttonSwallowCount(b) == 1) && b->flags & b_Hangon && + buttonSwallow(b) & b_UseOld) + if (b->spawn) { +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x did not find a \"%s\" " + "window, %s", + MyName, (ushort)b, b->hangon, + "spawning own\n"); +#endif + SendText(fd, b->spawn, 0); + } } /** *** process_message() *** Process window list messages **/ -void process_message(unsigned long type,unsigned long *body) +void +process_message(unsigned long type, unsigned long *body) { -# ifdef DEBUG_FVWM - DebugFvwmEvents(type); -# endif - panel_info *PanelIndex = MainPanel; - do - { - UberButton = PanelIndex->uber; - MyWindow = UberButton->IconWinParent; - - switch(type) - { - case M_NEW_DESK: - new_desk = body[0]; - RedrawWindow(NULL); - break; - case M_END_WINDOWLIST: - SpawnSome(); - RedrawWindow(NULL); - break; - case M_MAP: - swallow(body); - break; - case M_RES_NAME: - case M_RES_CLASS: - case M_WINDOW_NAME: - CheckForHangon(body); - break; - default: - break; - } - - } while ((PanelIndex = PanelIndex->next)); -} +#ifdef DEBUG_FVWM + DebugFvwmEvents(type); +#endif + panel_info *PanelIndex = MainPanel; + do { + UberButton = PanelIndex->uber; + MyWindow = UberButton->IconWinParent; + switch (type) { + case M_NEW_DESK: + new_desk = body[0]; + DrainDestroyEvents(); + RedrawWindow(NULL); + break; + case M_END_WINDOWLIST: + SpawnSome(); + DrainDestroyEvents(); + RedrawWindow(NULL); + break; + case M_MAP: + swallow(body); + break; + case M_RES_NAME: + case M_RES_CLASS: + case M_WINDOW_NAME: + CheckForHangon(body); + break; + default: + break; + } + } while ((PanelIndex = PanelIndex->next)); +} /* --------------------------------- swallow code -------------------------- */ @@ -1650,56 +1769,60 @@ void process_message(unsigned long type,unsigned long *body) *** CheckForHangon() *** Is the window here now? **/ -void CheckForHangon(unsigned long *body) +void +CheckForHangon(unsigned long *body) { - button_info *b,*ub=UberButton; - int button=-1; - ushort d; - char *cbody; - cbody = (char *)&body[3]; - - while(NextButton(&ub,&b,&button,0)) - if(b->flags&b_Hangon && strcmp(cbody,b->hangon)==0) - { - /* Is this a swallowing button in state 1? */ - if(buttonSwallowCount(b)==1) - { - b->swallow&=~b_Count; - b->swallow|=2; - b->IconWin=(Window)body[0]; - b->flags&=~b_Hangon; - - /* We get the parent of the window to compare with later... */ - b->IconWinParent= - GetRealGeometry(Dpy,b->IconWin, - &b->x,&b->y,&b->w,&b->h,&b->bw,&d); - -# ifdef DEBUG_HANGON - fprintf(stderr,"%s: Button 0x%06x %s 0x%lx \"%s\", parent 0x%lx\n", - MyName,(ushort)b,"will swallow window",body[0],cbody, - b->IconWinParent); -# endif - - if(buttonSwallow(b)&b_UseOld) - swallow(body); - } - else - { - /* Else it is an executing button with a confirmed kill */ -# ifdef DEBUG_HANGON - fprintf(stderr,"%s: Button 0x%06x %s 0x%lx \"%s\", released\n", - MyName,(int)b,"hung on window",body[0],cbody); -# endif - b->flags&=~b_Hangon; - free(b->hangon); - b->hangon=NULL; - RedrawButton(b,0); + button_info *b, *ub = UberButton; + int button = -1; + ushort d; + char *cbody; + cbody = (char *)&body[3]; + + while (NextButton(&ub, &b, &button, 0)) + if (b->flags & b_Hangon && strcmp(cbody, b->hangon) == 0) { + /* Is this a swallowing button in state 1? */ + if (buttonSwallowCount(b) == 1) { + b->swallow &= ~b_Count; + b->swallow |= 2; + b->IconWin = (Window)body[0]; + b->flags &= ~b_Hangon; + + /* We get the parent of the window to compare + * with later... */ + b->IconWinParent = + GetRealGeometry(Dpy, b->IconWin, &b->x, + &b->y, &b->w, &b->h, &b->bw, &d); + +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x %s 0x%lx \"%s\", parent " + "0x%lx\n", + MyName, (ushort)b, "will swallow window", + body[0], cbody, b->IconWinParent); +#endif - } - break; - } - else if(buttonSwallowCount(b)>=2 && (Window)body[0]==b->IconWin) - break; /* This window has already been swallowed by someone else! */ + if (buttonSwallow(b) & b_UseOld) + swallow(body); + } else { + /* Else it is an executing button with a confirmed kill + */ +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x %s 0x%lx \"%s\", " + "released\n", + MyName, (int)b, "hung on window", body[0], + cbody); +#endif + b->flags &= ~b_Hangon; + free(b->hangon); + b->hangon = NULL; + RedrawButton(b, 0); + } + break; + } else if (buttonSwallowCount(b) >= 2 && + (Window)body[0] == b->IconWin) + break; /* This window has already been swallowed by + someone else! */ } /** @@ -1707,102 +1830,130 @@ void CheckForHangon(unsigned long *body) *** Traverses window tree to find the real x,y of a window. Any simpler? *** Returns parent window, or None if failed. **/ -Window GetRealGeometry(Display *dpy,Window win,int *x,int *y,ushort *w, - ushort *h,ushort *bw,ushort *d) +Window +GetRealGeometry(Display *dpy, Window win, int *x, int *y, ushort *w, ushort *h, + ushort *bw, ushort *d) { - Window root; - Window rp=None; - Window *children; - unsigned int n; + Window root; + Window rp = None; + Window *children; + unsigned int n; - if(!XGetGeometry(dpy,win,&root,x,y,w,h,bw,d)) - return None; + if (!XGetGeometry(dpy, win, &root, x, y, w, h, bw, d)) + return None; - /* Now, x and y are not correct. They are parent relative, not root... */ - /* Hmm, ever heard of XTranslateCoordinates!? */ + /* Now, x and y are not correct. They are parent relative, not root... + */ + /* Hmm, ever heard of XTranslateCoordinates!? */ - XTranslateCoordinates(dpy,win,root,*x,*y,x,y,&rp); + XTranslateCoordinates(dpy, win, root, *x, *y, x, y, &rp); - XQueryTree(dpy,win,&root,&rp,&children,&n); - if (children) - XFree(children); + if (XQueryTree(dpy, win, &root, &rp, &children, &n) && children) + XFree(children); - return rp; + return rp; } /** *** swallow() *** Executed when swallowed windows get mapped **/ -void swallow(unsigned long *body) +void +swallow(unsigned long *body) { - char *temp; - button_info *ub=UberButton,*b; - int button=-1; - ushort d; - Window p; - - while(NextButton(&ub,&b,&button,0)) - if((b->IconWin==(Window)body[0]) && (buttonSwallowCount(b)==2)) - { - /* Store the geometry in case we need to unswallow. Get parent */ - p=GetRealGeometry(Dpy,b->IconWin,&b->x,&b->y,&b->w,&b->h,&b->bw,&d); -# ifdef DEBUG_HANGON - fprintf(stderr,"%s: Button 0x%06x %s 0x%lx, with parent 0x%lx\n", - MyName,(ushort)b,"trying to swallow window",body[0],p); -# endif - - if(p==None) /* This means the window is no more */ /* NO! wrong */ - { - fprintf(stderr,"%s: Window 0x%lx (\"%s\") disappeared %s\n", - MyName,b->IconWin,b->hangon,"before swallow complete"); - /* Now what? Nothing? For now: give up that button */ - b->flags&=~(b_Hangon|b_Swallow); - return; - } - - if(p!=b->IconWinParent) /* The window has been reparented */ - { - fprintf(stderr,"%s: Window 0x%lx (\"%s\") was %s (window 0x%lx)\n", - MyName,b->IconWin,b->hangon,"grabbed by someone else",p); - - /* Request a new windowlist, we might have ignored another - matching window.. */ - SendText(fd,"Send_WindowList",0); - - /* Back one square and lose one turn */ - b->swallow&=~b_Count; - b->swallow|=1; - b->flags|=b_Hangon; - return; - } - -# ifdef DEBUG_HANGON - fprintf(stderr,"%s: Button 0x%06x swallowed window 0x%lx\n", - MyName,(ushort)b,body[0]); -# endif + char *temp; + button_info *ub = UberButton, *b; + int button = -1; + ushort d; + Window p; + + while (NextButton(&ub, &b, &button, 0)) + if ((b->IconWin == (Window)body[0]) && + (buttonSwallowCount(b) == 2)) { + /* Store the geometry in case we need to unswallow. Get + * parent */ + p = GetRealGeometry(Dpy, b->IconWin, &b->x, &b->y, + &b->w, &b->h, &b->bw, &d); +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x %s 0x%lx, with parent 0x%lx\n", + MyName, (ushort)b, "trying to swallow window", + body[0], p); +#endif - b->swallow&=~b_Count; - b->swallow|=3; + if (p == + None) { /* This means the window is no more */ /* NO! + wrong + */ + fprintf(stderr, + "%s: Window 0x%lx (\"%s\") disappeared " + "%s\n", + MyName, b->IconWin, b->hangon, + "before swallow complete"); + /* Now what? Nothing? For now: give up that + * button */ + b->flags &= ~(b_Hangon | b_Swallow); + return; + } + + if (p != b->IconWinParent) { /* The window has been + reparented */ + fprintf(stderr, + "%s: Window 0x%lx (\"%s\") was %s (window " + "0x%lx)\n", + MyName, b->IconWin, b->hangon, + "grabbed by someone else", p); + + /* Request a new windowlist, we might have + ignored another matching window.. */ + SendText(fd, "Send_WindowList", 0); + + /* Back one square and lose one turn */ + b->swallow &= ~b_Count; + b->swallow |= 1; + b->flags |= b_Hangon; + return; + } + +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x swallowed window 0x%lx\n", + MyName, (ushort)b, body[0]); +#endif - /* "Swallow" the window! Place it in the void so we don't see it - until it's MoveResize'd */ - XReparentWindow(Dpy,b->IconWin,MyWindow,-1500,-1500); - XSelectInput(Dpy,b->IconWin,SW_EVENTS); - if(buttonSwallow(b)&b_UseTitle) - { - if(b->flags&b_Title) - free(b->title); - b->flags|=b_Title; - XFetchName(Dpy,b->IconWin,&temp); - CopyString(&b->title,temp); - XFree(temp); - } - XMapWindow(Dpy,b->IconWin); - MakeButton(b); - RedrawButton(b,1); - break; - } + b->swallow &= ~b_Count; + b->swallow |= 3; + + /* "Swallow" the window! Place it in the void so we + don't see it until it's MoveResize'd */ + XGrabServer(Dpy); + p = GetRealGeometry(Dpy, b->IconWin, &b->x, + &b->y, &b->w, &b->h, &b->bw, &d); + if (p != None) { + XReparentWindow(Dpy, b->IconWin, MyWindow, + -1500, -1500); + XSync(Dpy, False); + XSelectInput(Dpy, b->IconWin, SW_EVENTS); + if (buttonSwallow(b) & b_UseTitle) { + if (b->flags & b_Title) + free(b->title); + b->flags |= b_Title; + XFetchName(Dpy, b->IconWin, &temp); + CopyString(&b->title, temp); + XFree(temp); + } + XMapWindow(Dpy, b->IconWin); + MakeButton(b); + RedrawButton(b, 1); + } else { + fprintf(stderr, + "%s: Window 0x%lx disappeared during %s\n", + MyName, b->IconWin, "swallow"); + b->flags &= ~(b_Hangon | b_Swallow); + } + XUngrabServer(Dpy); + break; + } } /* @@ -1830,172 +1981,158 @@ void swallow(unsigned long *body) #define PanelPopUpStep 32 -panel_info *seekpanel (button_info *b) +panel_info * +seekpanel(button_info *b) { - panel_info *PanelIndex = MainPanel->next; /* skip the main panel */ + panel_info *PanelIndex = MainPanel->next; /* skip the main panel */ - while (PanelIndex && strcmp(b->hangon, PanelIndex->uber->title)) - PanelIndex = PanelIndex->next; + while (PanelIndex && strcmp(b->hangon, PanelIndex->uber->title)) + PanelIndex = PanelIndex->next; - return PanelIndex; + return PanelIndex; } -void Slide (panel_info *p, button_info *b) +void +Slide(panel_info *p, button_info *b) { - Window PanelWin; - Window root; - int x, y, iw, ih, BW, depth; - char direction; - ushort i, c, xstep, ystep, wstep, hstep; - - if (!p) - /* no such panel */ - return; - /* PanelWin is found */ - PanelWin = p->uber->IconWinParent; - - direction = b ? b->action[0][6] : (char) p->uber->n; - - if (p->uber->swallow) - { - /* shown ---> hidden */ - root = GetRealGeometry(Dpy, PanelWin, &x, &y, - (ushort*)&iw, (ushort*)&ih, - (ushort*)&BW, (ushort*)&depth); - - switch (direction) - { - case 'l': - c = iw / PanelPopUpStep; - xstep = wstep = PanelPopUpStep; - ystep = hstep = 0; - break; - case 'r': - c = iw / PanelPopUpStep; - wstep = PanelPopUpStep; - xstep = ystep = hstep = 0; - break; - case 'd': - c = ih / PanelPopUpStep; - hstep = PanelPopUpStep; - xstep = ystep = wstep = 0; - break; - case 'g': - /* just pop down without animation */ - c = 0; - break; - case 'u': - default: - c = ih / PanelPopUpStep; - ystep = hstep = PanelPopUpStep; - xstep = wstep = 0; - break; - } - - for (i = 1; i < c; i++) - { - iw -= wstep; - ih -= hstep; - x += xstep; - y += ystep; - XMoveResizeWindow(Dpy, PanelWin, x, y, iw, ih); - } - - XUnmapWindow(Dpy, PanelWin); - p->uber->swallow = 0; - } - else - { - /* hidden ---> shown */ - int ix = buttonXPos(b, b->n); /* button in the CurrentPanel */ - int iy = buttonYPos(b, b->n); /* button in the CurrentPanel */ - - int mw = p->uber->icon_w; /* panel menu width */ - int mh = p->uber->icon_h; /* panel menu height */ - int w; /* current width */ - int h; /* current height */ - - root = GetRealGeometry(Dpy, CurrentPanel->uber->IconWinParent, &x, &y, - (ushort*)&iw, (ushort*)&ih, - (ushort*)&BW, (ushort*)&depth); - - x += p->uber->x + ix; - y += p->uber->y + iy; - c = 0; - - /* initial position and size */ - switch (direction) - { - case 'g': - /* just pop up without animation */ - c = 0; - break; - case 'l': - case 'r': - h = mh; - w = mw % PanelPopUpStep; - if (w == 0) - { - w = PanelPopUpStep; - c--; - } - if (direction == 'l') - { - x -= w; - c += mw / PanelPopUpStep; - xstep = wstep = PanelPopUpStep; - ystep = hstep = 0; - } - else - { - x += b->BWidth * b->parent->c->ButtonWidth; - c += mw / PanelPopUpStep; - wstep = PanelPopUpStep; - xstep = ystep = hstep = 0; - } - break; - case 'd': - case 'u': - default: - w = mw; - h = mh % PanelPopUpStep; - if (h == 0) - { - h = PanelPopUpStep; - c--; - } - if (direction == 'd') - { - y += b->BHeight * b->parent->c->ButtonHeight; - c += mh / PanelPopUpStep; - hstep = PanelPopUpStep; - xstep = ystep = wstep = 0; - } - else - { - y -= h; - c += mh / PanelPopUpStep; - ystep = hstep = PanelPopUpStep; - xstep = wstep = 0; - } - break; - } - - if (c > 0) - XMoveResizeWindow(Dpy, PanelWin, x, y, w, h); - XMapSubwindows(Dpy, PanelWin); - XMapWindow(Dpy, PanelWin); - - for (i = 0; i < c; i++) - { - x -= xstep; - w += wstep; - y -= ystep; - h += hstep; - XMoveResizeWindow(Dpy, PanelWin, x, y, w, h); - } - - p->uber->n = (int) direction; - p->uber->swallow = 1; - } + Window PanelWin; + Window root; + int x, y, iw, ih, BW, depth; + char direction; + ushort i, c, xstep, ystep, wstep, hstep; + + if (!p) + /* no such panel */ + return; + /* PanelWin is found */ + PanelWin = p->uber->IconWinParent; + + direction = b ? b->action[0][6] : (char)p->uber->n; + + if (p->uber->swallow) { + /* shown ---> hidden */ + root = GetRealGeometry(Dpy, PanelWin, &x, &y, (ushort *)&iw, + (ushort *)&ih, (ushort *)&BW, (ushort *)&depth); + + switch (direction) { + case 'l': + c = iw / PanelPopUpStep; + xstep = wstep = PanelPopUpStep; + ystep = hstep = 0; + break; + case 'r': + c = iw / PanelPopUpStep; + wstep = PanelPopUpStep; + xstep = ystep = hstep = 0; + break; + case 'd': + c = ih / PanelPopUpStep; + hstep = PanelPopUpStep; + xstep = ystep = wstep = 0; + break; + case 'g': + /* just pop down without animation */ + c = 0; + break; + case 'u': + default: + c = ih / PanelPopUpStep; + ystep = hstep = PanelPopUpStep; + xstep = wstep = 0; + break; + } + + for (i = 1; i < c; i++) { + iw -= wstep; + ih -= hstep; + x += xstep; + y += ystep; + XMoveResizeWindow(Dpy, PanelWin, x, y, iw, ih); + } + + XUnmapWindow(Dpy, PanelWin); + p->uber->swallow = 0; + } else { + /* hidden ---> shown */ + int ix = buttonXPos(b, b->n); /* button in the CurrentPanel */ + int iy = buttonYPos(b, b->n); /* button in the CurrentPanel */ + + int mw = p->uber->icon_w; /* panel menu width */ + int mh = p->uber->icon_h; /* panel menu height */ + int w; /* current width */ + int h; /* current height */ + + root = GetRealGeometry(Dpy, CurrentPanel->uber->IconWinParent, + &x, &y, (ushort *)&iw, (ushort *)&ih, (ushort *)&BW, + (ushort *)&depth); + + x += p->uber->x + ix; + y += p->uber->y + iy; + c = 0; + + /* initial position and size */ + switch (direction) { + case 'g': + /* just pop up without animation */ + c = 0; + break; + case 'l': + case 'r': + h = mh; + w = mw % PanelPopUpStep; + if (w == 0) { + w = PanelPopUpStep; + c--; + } + if (direction == 'l') { + x -= w; + c += mw / PanelPopUpStep; + xstep = wstep = PanelPopUpStep; + ystep = hstep = 0; + } else { + x += b->BWidth * b->parent->c->ButtonWidth; + c += mw / PanelPopUpStep; + wstep = PanelPopUpStep; + xstep = ystep = hstep = 0; + } + break; + case 'd': + case 'u': + default: + w = mw; + h = mh % PanelPopUpStep; + if (h == 0) { + h = PanelPopUpStep; + c--; + } + if (direction == 'd') { + y += b->BHeight * b->parent->c->ButtonHeight; + c += mh / PanelPopUpStep; + hstep = PanelPopUpStep; + xstep = ystep = wstep = 0; + } else { + y -= h; + c += mh / PanelPopUpStep; + ystep = hstep = PanelPopUpStep; + xstep = wstep = 0; + } + break; + } + + if (c > 0) + XMoveResizeWindow(Dpy, PanelWin, x, y, w, h); + XMapSubwindows(Dpy, PanelWin); + XMapWindow(Dpy, PanelWin); + + for (i = 0; i < c; i++) { + x -= xstep; + w += wstep; + y -= ystep; + h += hstep; + XMoveResizeWindow(Dpy, PanelWin, x, y, w, h); + } + + p->uber->n = (int)direction; + p->uber->swallow = 1; + } } Index: fvwm/modules/FvwmButtons/FvwmButtons.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/FvwmButtons.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/FvwmButtons.h --- fvwm/modules/FvwmButtons/FvwmButtons.h +++ fvwm/modules/FvwmButtons/FvwmButtons.h @@ -25,12 +25,12 @@ #define DEBUG_HANGON /* Debug hangon, swallow and unswallow */ /* #define DEBUG_EVENTS */ /* Get much info on events */ #define DEBUG_FVWM /* Debug communciation with fvwm */ -/* #define DEBUG_X */ +/* #define DEBUG_X */ #endif /* ---------------------------- compatibility ------------------------------ */ -#define OLD_EXPOSE /* Try this if resizing/exposes screw up */ +#define OLD_EXPOSE /* Try this if resizing/exposes screw up */ /* -------------------------------- more ---------------------------------- */ @@ -39,42 +39,44 @@ /* ------------------------------- structs --------------------------------- */ /* flags for b->flags */ -#define b_Container 0x00000001 /* Contains several buttons */ -#define b_Font 0x00000002 /* Has personal font data */ -#define b_Fore 0x00000004 /* Has personal text color */ -#define b_Back 0x00000008 /* Has personal background color (or "none")*/ -#define b_Padding 0x00000010 /* Has personal padding data */ -#define b_Frame 0x00000020 /* Has personal framewidth */ -#define b_Title 0x00000040 /* Contains title */ -#define b_Icon 0x00000080 /* Contains icon */ -#define b_Swallow 0x00000100 /* Contains swallowed window */ -#define b_Action 0x00000200 /* Fvwm action when clicked on */ -#define b_Hangon 0x00000400 /* Is waiting for a window before turning - * active */ -#define b_Justify 0x00000800 /* Has justification info */ -#define b_Size 0x00001000 /* Has a minimum size, don't guess */ -#define b_IconBack 0x00002000 /* Has an icon as background */ +#define b_Container 0x00000001 /* Contains several buttons */ +#define b_Font 0x00000002 /* Has personal font data */ +#define b_Fore 0x00000004 /* Has personal text color */ +#define b_Back 0x00000008 /* Has personal background color (or "none")*/ +#define b_Padding 0x00000010 /* Has personal padding data */ +#define b_Frame 0x00000020 /* Has personal framewidth */ +#define b_Title 0x00000040 /* Contains title */ +#define b_Icon 0x00000080 /* Contains icon */ +#define b_Swallow 0x00000100 /* Contains swallowed window */ +#define b_Action 0x00000200 /* Fvwm action when clicked on */ +#define b_Hangon \ + 0x00000400 /* Is waiting for a window before turning\ + * active */ +#define b_Justify 0x00000800 /* Has justification info */ +#define b_Size 0x00001000 /* Has a minimum size, don't guess */ +#define b_IconBack 0x00002000 /* Has an icon as background */ #define b_IconParent 0x00004000 /* Parent button has an icon as background */ -#define b_TransBack 0x00008000 /* Transparent background */ -#define b_Left 0x00010000 /* Button is left-aligned */ -#define b_Right 0x00020000 /* Button is right-aligned */ -#define b_SizeFixed 0x00040000 /* User provided rows/columns may not be - * altered */ -#define b_PosFixed 0x00080000 /* User provided button position */ -#define b_SizeSmart 0x00100000 /* Improved button box sizing */ +#define b_TransBack 0x00008000 /* Transparent background */ +#define b_Left 0x00010000 /* Button is left-aligned */ +#define b_Right 0x00020000 /* Button is right-aligned */ +#define b_SizeFixed \ + 0x00040000 /* User provided rows/columns may not be \ + * altered */ +#define b_PosFixed 0x00080000 /* User provided button position */ +#define b_SizeSmart 0x00100000 /* Improved button box sizing */ /* Flags for b->swallow */ -#define b_Count 0x03 /* Init counter for swallowing */ -#define b_NoHints 0x04 /* Ignore window hints from swallowed window */ -#define b_NoClose 0x08 /* Don't close window when exiting, unswallow it */ -#define b_Kill 0x10 /* Don't close window when exiting, kill it */ -#define b_Respawn 0x20 /* Respawn if swallowed window dies */ -#define b_UseOld 0x40 /* Try to capture old window, don't spawn it */ -#define b_UseTitle 0x80 /* Allow window to write to b->title */ +#define b_Count 0x03 /* Init counter for swallowing */ +#define b_NoHints 0x04 /* Ignore window hints from swallowed window */ +#define b_NoClose 0x08 /* Don't close window when exiting, unswallow it */ +#define b_Kill 0x10 /* Don't close window when exiting, kill it */ +#define b_Respawn 0x20 /* Respawn if swallowed window dies */ +#define b_UseOld 0x40 /* Try to capture old window, don't spawn it */ +#define b_UseTitle 0x80 /* Allow window to write to b->title */ /* Flags for b->justify */ -#define b_TitleHoriz 0x03 /* Mask for title x positioning info */ -#define b_Horizontal 0x04 /* HACK: stack title and iconwin horizontally */ +#define b_TitleHoriz 0x03 /* Mask for title x positioning info */ +#define b_Horizontal 0x04 /* HACK: stack title and iconwin horizontally */ typedef struct panel_info_struct panel_info; typedef struct button_info_struct button_info; @@ -83,90 +85,85 @@ typedef struct container_info_struct container_info; #define byte unsigned char /* This structure contains data that the parents give their children */ -struct container_info_struct -{ - button_info **buttons; /* Required fields */ - int allocated_buttons; - int num_buttons; - int num_columns; - int num_rows; - int ButtonWidth; - int ButtonHeight; - int xpos,ypos; - - unsigned long flags; /* Which data are set in this container? */ - byte justify; /* b_Justify */ - byte justify_mask; /* b_Justify */ - byte swallow; /* b_Swallow */ - byte swallow_mask; /* b_Swallow */ - byte xpad,ypad; /* b_Padding */ - signed char framew; /* b_Frame */ - XFontStruct *font; /* b_Font */ - char *font_string; /* b_Font */ - char *back; /* b_Back && !b_IconBack */ - char *back_file; /* b_Back && b_IconBack */ - char *fore; /* b_Fore */ - Pixel fc; /* b_Fore */ - Pixel bc,hc,sc; /* b_Back && !b_IconBack */ - FvwmPicture *backicon; /* b_Back && b_IconBack */ - ushort minx,miny; /* b_Size */ +struct container_info_struct { + button_info **buttons; /* Required fields */ + int allocated_buttons; + int num_buttons; + int num_columns; + int num_rows; + int ButtonWidth; + int ButtonHeight; + int xpos, ypos; + + unsigned long flags; /* Which data are set in this container? */ + byte justify; /* b_Justify */ + byte justify_mask; /* b_Justify */ + byte swallow; /* b_Swallow */ + byte swallow_mask; /* b_Swallow */ + byte xpad, ypad; /* b_Padding */ + signed char framew; /* b_Frame */ + XFontStruct *font; /* b_Font */ + char *font_string; /* b_Font */ + char *back; /* b_Back && !b_IconBack */ + char *back_file; /* b_Back && b_IconBack */ + char *fore; /* b_Fore */ + Pixel fc; /* b_Fore */ + Pixel bc, hc, sc; /* b_Back && !b_IconBack */ + FvwmPicture *backicon; /* b_Back && b_IconBack */ + ushort minx, miny; /* b_Size */ }; -struct button_info_struct -{ - /* required fields */ - unsigned long flags; - int BPosX,BPosY; /* position in button units from top left */ - byte BWidth,BHeight; /* width and height in button units */ - button_info *parent; - int n; /* number in parent */ - - /* conditional fields */ /* applicable if these flags are set */ - XFontStruct *font; /* b_Font */ - char *font_string; /* b_Font */ - char *back; /* b_Back */ - char *fore; /* b_Fore */ - byte xpad,ypad; /* b_Padding */ - signed char framew; /* b_Frame */ - byte justify; /* b_Justify */ - byte justify_mask; /* b_Justify */ - container_info *c; /* b_Container */ - char *title; /* b_Title */ - char **action; /* b_Action */ - char *icon_file; /* b_Icon */ - char *hangon; /* b_Hangon || b_Swallow */ - Window IconWin; /* b_Icon || b_Swallow */ - Pixel fc; /* b_Fore */ - Pixel bc,hc,sc; /* b_Back && !b_IconBack */ - FvwmPicture *backicon; /* b_Back && b_IconBack */ - ushort minx,miny; /* b_Size */ - FvwmPicture *icon; /* b_Icon */ - - byte swallow; /* b_Swallow */ - byte swallow_mask; /* b_Swallow */ - int icon_w,icon_h; /* b_Swallow */ - Window IconWinParent; /* b_Swallow */ - XSizeHints *hints; /* b_Swallow && !b_NoHints */ - char *spawn; /* b_Swallow */ - int x,y; /* b_Swallow */ - ushort w,h,bw; /* b_Swallow */ +struct button_info_struct { + /* required fields */ + unsigned long flags; + int BPosX, BPosY; /* position in button units from top left */ + byte BWidth, BHeight; /* width and height in button units */ + button_info *parent; + int n; /* number in parent */ + + /* conditional fields */ /* applicable if these flags are set */ + XFontStruct *font; /* b_Font */ + char *font_string; /* b_Font */ + char *back; /* b_Back */ + char *fore; /* b_Fore */ + byte xpad, ypad; /* b_Padding */ + signed char framew; /* b_Frame */ + byte justify; /* b_Justify */ + byte justify_mask; /* b_Justify */ + container_info *c; /* b_Container */ + char *title; /* b_Title */ + char **action; /* b_Action */ + char *icon_file; /* b_Icon */ + char *hangon; /* b_Hangon || b_Swallow */ + Window IconWin; /* b_Icon || b_Swallow */ + Pixel fc; /* b_Fore */ + Pixel bc, hc, sc; /* b_Back && !b_IconBack */ + FvwmPicture *backicon; /* b_Back && b_IconBack */ + ushort minx, miny; /* b_Size */ + FvwmPicture *icon; /* b_Icon */ + + byte swallow; /* b_Swallow */ + byte swallow_mask; /* b_Swallow */ + int icon_w, icon_h; /* b_Swallow */ + Window IconWinParent; /* b_Swallow */ + XSizeHints *hints; /* b_Swallow && !b_NoHints */ + char *spawn; /* b_Swallow */ + int x, y; /* b_Swallow */ + ushort w, h, bw; /* b_Swallow */ }; -struct panel_info_struct -{ button_info *uber; /* panel */ - panel_info *next; +struct panel_info_struct { + button_info *uber; /* panel */ + panel_info *next; + int geom_w; /* requested width, -1 if unset */ + int geom_h; /* requested height, -1 if unset */ }; #include "button.h" /* -------------------------------- prototypes ----------------------------- */ -void AddButtonAction(button_info*,int,char*); -void MakeContainer(button_info*); -#ifdef DEBUG -char *mymalloc(int); -#else -#define mymalloc(a) safemalloc(a) -#endif +void AddButtonAction(button_info *, int, char *); +void MakeContainer(button_info *); /* ----------------------------- global variables -------------------------- */ @@ -174,7 +171,7 @@ extern Display *Dpy; extern Window Root; extern Window MyWindow; extern char *MyName; -extern button_info *UberButton,*CurrentButton; +extern button_info *UberButton, *CurrentButton; extern panel_info *MainPanel, *CurrentPanel; extern char *iconPath; @@ -184,8 +181,7 @@ extern int fd[]; extern int screen; extern int d_depth; extern int new_desk; -extern GC NormalGC; -extern int x,y,xneg,yneg,w,h; /* Dirty... */ +extern GC NormalGC; +extern int x, y, xneg, yneg, w, h; /* Dirty... */ /* ---------------------------------- misc --------------------------------- */ - Index: fvwm/modules/FvwmButtons/button.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/button.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/button.c --- fvwm/modules/FvwmButtons/button.c +++ fvwm/modules/FvwmButtons/button.c @@ -12,11 +12,12 @@ */ -#include +#include #include -#include #include -#include +#include +#include + #include "FvwmButtons.h" extern char *MyName; @@ -25,247 +26,252 @@ extern char *MyName; *** buttonInfo() *** Give lots of info for this button: XPos, YPos, XPad, YPad, Frame(signed) **/ -void buttonInfo(button_info *b,int *x,int *y,int *px,int *py,int *f) +void +buttonInfo(button_info *b, int *x, int *y, int *px, int *py, int *f) { - ushort w=b_Padding|b_Frame; - *x=buttonXPos(b,b->n); - *y=buttonYPos(b,b->n); - *px=b->xpad; - *py=b->ypad; - *f=b->framew; - w&=~(b->flags&(b_Frame|b_Padding)); - - if(b->flags&b_Container && w&b_Frame) - { - *f=0; - w&=~b_Frame; - } - if((b->flags&b_Container || b->flags&b_Swallow) && w&b_Padding) - { - *px=*py=0; - w&=~b_Padding; - } - - while(w && (b=b->parent)) - { - if(w&b_Frame && b->c->flags&b_Frame) - { - *f=b->c->framew; - w&=~b_Frame; + ushort w = b_Padding | b_Frame; + *x = buttonXPos(b, b->n); + *y = buttonYPos(b, b->n); + *px = b->xpad; + *py = b->ypad; + *f = b->framew; + w &= ~(b->flags & (b_Frame | b_Padding)); + + if (b->flags & b_Container && w & b_Frame) { + *f = 0; + w &= ~b_Frame; + } + if ((b->flags & b_Container || b->flags & b_Swallow) && w & b_Padding) { + *px = *py = 0; + w &= ~b_Padding; } - if(w&b_Padding && b->c->flags&b_Padding) - { - *px=b->c->xpad; - *py=b->c->ypad; - w&=~b_Padding; + + while (w && (b = b->parent)) { + if (w & b_Frame && b->c->flags & b_Frame) { + *f = b->c->framew; + w &= ~b_Frame; + } + if (w & b_Padding && b->c->flags & b_Padding) { + *px = b->c->xpad; + *py = b->c->ypad; + w &= ~b_Padding; + } } - } } /** *** GetInternalSize() **/ -void GetInternalSize(button_info *b,int *x,int *y,int *w,int *h) +void +GetInternalSize(button_info *b, int *x, int *y, int *w, int *h) { - int f; - int px,py; - buttonInfo(b,x,y,&px,&py,&f); - f=abs(f); + int f; + int px, py; + buttonInfo(b, x, y, &px, &py, &f); + f = abs(f); - *w=buttonWidth(b)-2*(px+f); - *h=buttonHeight(b)-2*(py+f); + *w = buttonWidth(b) - 2 * (px + f); + *h = buttonHeight(b) - 2 * (py + f); - *x+=f+px; - *y+=f+py; + *x += f + px; + *y += f + py; - if(*w<=1 || *h<=1) - *w=*h=1; + if (*w <= 1 || *h <= 1) + *w = *h = 1; } /** *** buttonFrameSigned() *** Give the signed framewidth for this button. **/ -int buttonFrameSigned(button_info *b) +int +buttonFrameSigned(button_info *b) { - if(b->flags&b_Frame) - return b->framew; - if(b->flags&b_Container) /* Containers usually gets 0 relief */ - return 0; - while((b=b->parent)) - if(b->c->flags&b_Frame) - return b->c->framew; + if (b->flags & b_Frame) + return b->framew; + if (b->flags & b_Container) /* Containers usually gets 0 relief */ + return 0; + while ((b = b->parent)) + if (b->c->flags & b_Frame) + return b->c->framew; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No relief width definition?\n",MyName); + fprintf(stderr, "%s: BUG: No relief width definition?\n", MyName); #endif - return 0; + return 0; } /** *** buttonXPad() *** Give the x padding for this button **/ -int buttonXPad(button_info *b) +int +buttonXPad(button_info *b) { - if(b->flags&b_Padding) - return b->xpad; - if(b->flags&(b_Container|b_Swallow)) /* Normally no padding for these */ - return 0; - while((b=b->parent)) - if(b->c->flags&b_Padding) - return b->c->xpad; + if (b->flags & b_Padding) + return b->xpad; + if (b->flags & + (b_Container | b_Swallow)) /* Normally no padding for these */ + return 0; + while ((b = b->parent)) + if (b->c->flags & b_Padding) + return b->c->xpad; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No padding definition?\n",MyName); + fprintf(stderr, "%s: BUG: No padding definition?\n", MyName); #endif - return 0; + return 0; } /** *** buttonYPad() *** Give the y padding for this button **/ -int buttonYPad(button_info *b) +int +buttonYPad(button_info *b) { - if(b->flags&b_Padding) - return b->ypad; - if(b->flags&(b_Container|b_Swallow)) /* Normally no padding for these */ - return 0; - while((b=b->parent)) - if(b->c->flags&b_Padding) - return b->c->ypad; + if (b->flags & b_Padding) + return b->ypad; + if (b->flags & + (b_Container | b_Swallow)) /* Normally no padding for these */ + return 0; + while ((b = b->parent)) + if (b->c->flags & b_Padding) + return b->c->ypad; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No padding definition?\n",MyName); + fprintf(stderr, "%s: BUG: No padding definition?\n", MyName); #endif - return 0; + return 0; } /** *** buttonFont() *** Give the font pointer for this button **/ -XFontStruct *buttonFont(button_info *b) +XFontStruct * +buttonFont(button_info *b) { - if(b->flags&b_Font) - return b->font; - while((b=b->parent)) - if(b->c->flags&b_Font) - return b->c->font; + if (b->flags & b_Font) + return b->font; + while ((b = b->parent)) + if (b->c->flags & b_Font) + return b->c->font; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No font definition?\n",MyName); + fprintf(stderr, "%s: BUG: No font definition?\n", MyName); #endif - return None; + return None; } /** *** buttonFore() *** Give the foreground pixel of this button **/ -Pixel buttonFore(button_info *b) +Pixel +buttonFore(button_info *b) { - if(b->flags&b_Fore) - return b->fc; - while((b=b->parent)) - if(b->c->flags&b_Fore) - return b->c->fc; + if (b->flags & b_Fore) + return b->fc; + while ((b = b->parent)) + if (b->c->flags & b_Fore) + return b->c->fc; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No foreground definition?\n",MyName); + fprintf(stderr, "%s: BUG: No foreground definition?\n", MyName); #endif - return None; + return None; } /** *** buttonBack() *** Give the background pixel of this button **/ -Pixel buttonBack(button_info *b) +Pixel +buttonBack(button_info *b) { - if(b->flags&b_Back) - return b->bc; - while((b=b->parent)) - if(b->c->flags&b_Back) - return b->c->bc; + if (b->flags & b_Back) + return b->bc; + while ((b = b->parent)) + if (b->c->flags & b_Back) + return b->c->bc; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No background definition?\n",MyName); + fprintf(stderr, "%s: BUG: No background definition?\n", MyName); #endif - return None; + return None; } /** *** buttonHilite() *** Give the relief pixel of this button **/ -Pixel buttonHilite(button_info *b) +Pixel +buttonHilite(button_info *b) { - if(b->flags&b_Back) - return b->hc; - while((b=b->parent)) - if(b->c->flags&b_Back) - return b->c->hc; + if (b->flags & b_Back) + return b->hc; + while ((b = b->parent)) + if (b->c->flags & b_Back) + return b->c->hc; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No background definition?\n",MyName); + fprintf(stderr, "%s: BUG: No background definition?\n", MyName); #endif - return None; + return None; } /** *** buttonShadow() *** Give the shadow pixel of this button **/ -Pixel buttonShadow(button_info *b) +Pixel +buttonShadow(button_info *b) { - if(b->flags&b_Back) - return b->sc; - while((b=b->parent)) - if(b->c->flags&b_Back) - return b->c->sc; + if (b->flags & b_Back) + return b->sc; + while ((b = b->parent)) + if (b->c->flags & b_Back) + return b->c->sc; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No background definition?\n",MyName); + fprintf(stderr, "%s: BUG: No background definition?\n", MyName); #endif - return None; + return None; } /** *** buttonSwallow() *** Give the swallowing flags for this button **/ -byte buttonSwallow(button_info *b) +byte +buttonSwallow(button_info *b) { - byte s=0,t=0; - if(b->flags&b_Swallow) - { - s=b->swallow; - t=b->swallow_mask; - } - while((b=b->parent)) - if(b->c->flags&b_Swallow) - { - s&=~(b->c->swallow_mask&~t); - s|=(b->c->swallow&b->c->swallow_mask&~t); - t|=b->c->swallow_mask; - } - return s; + byte s = 0, t = 0; + if (b->flags & b_Swallow) { + s = b->swallow; + t = b->swallow_mask; + } + while ((b = b->parent)) + if (b->c->flags & b_Swallow) { + s &= ~(b->c->swallow_mask & ~t); + s |= (b->c->swallow & b->c->swallow_mask & ~t); + t |= b->c->swallow_mask; + } + return s; } /** *** buttonJustify() *** Give the justify flags for this button **/ -byte buttonJustify(button_info *b) +byte +buttonJustify(button_info *b) { - byte j=1,i=0; - if(b->flags&b_Justify) - { - i=b->justify_mask; - j=b->justify; - } - while((b=b->parent)) - if(b->c->flags&b_Justify) - { - j&=~(b->c->justify_mask&~i); - j|=(b->c->justify&b->c->justify_mask&~i); - i|=b->c->justify_mask; - } - return j; + byte j = 1, i = 0; + if (b->flags & b_Justify) { + i = b->justify_mask; + j = b->justify; + } + while ((b = b->parent)) + if (b->c->flags & b_Justify) { + j &= ~(b->c->justify_mask & ~i); + j |= (b->c->justify & b->c->justify_mask & ~i); + i |= b->c->justify_mask; + } + return j; } /* ---------------------------- button creation ---------------------------- */ @@ -275,32 +281,32 @@ byte buttonJustify(button_info *b) *** Makes sure the list of butten_info's is long enough, if not it reallocates *** a longer one. This happens in steps of 32. Inital length is 0. **/ -void alloc_buttonlist(button_info *ub,int num) +void +alloc_buttonlist(button_info *ub, int num) { - button_info **bb; - int i,old; - - if(num>=ub->c->allocated_buttons) - { - old=ub->c->allocated_buttons; - if(numc->allocated_buttons<=num) - ub->c->allocated_buttons+=32; - bb=(button_info**) - mymalloc(ub->c->allocated_buttons*sizeof(button_info*)); - for(i=old;ic->allocated_buttons;i++) - bb[i]=NULL; - if(ub->c->buttons) - { - for(i=0;ic->buttons[i]; - free(ub->c->buttons); + button_info **bb; + int i, old; + + if (num >= ub->c->allocated_buttons) { + old = ub->c->allocated_buttons; + if (num < old || old + 32 < old) { + fprintf(stderr, + "%s: Too many buttons, integer overflow\n", MyName); + exit(1); + } + while (ub->c->allocated_buttons <= num) + ub->c->allocated_buttons += 32; + bb = (button_info **)xmalloc( + ub->c->allocated_buttons * sizeof(button_info *)); + for (i = old; i < ub->c->allocated_buttons; i++) + bb[i] = NULL; + if (ub->c->buttons) { + for (i = 0; i < old; i++) + bb[i] = ub->c->buttons[i]; + free(ub->c->buttons); + } + ub->c->buttons = bb; } - ub->c->buttons=bb; - } } /** @@ -308,71 +314,71 @@ void alloc_buttonlist(button_info *ub,int num) *** Allocates memory for a new button struct. Calles alloc_buttonlist to *** assure enough space is present. Also initiates most elements of the struct. **/ -button_info *alloc_button(button_info *ub,int num) +button_info * +alloc_button(button_info *ub, int num) { - button_info *b; - if(num>=ub->c->allocated_buttons) - alloc_buttonlist(ub,num); - if(ub->c->buttons[num]) - { - fprintf(stderr,"%s: Allocated button twice, report bug twice\n",MyName); - exit(2); - } - - b=(button_info*)mymalloc(sizeof(button_info)); - ub->c->buttons[num]=b; - - memset((void *)b, 0, sizeof(*b)); - b->flags = 0; - b->swallow = 0; - b->BWidth = b->BHeight = 1; - b->BPosX = b->BPosY = 0; - b->parent = ub; - b->n = -1; - b->IconWin = 0; - - b->framew = 1; - b->xpad = 2; - b->ypad = 4; - b->w=1; - b->h=1; - b->bw=1; - - return(b); + button_info *b; + if (num >= ub->c->allocated_buttons) + alloc_buttonlist(ub, num); + if (ub->c->buttons[num]) { + fprintf(stderr, + "%s: Allocated button twice, report bug twice\n", MyName); + exit(2); + } + + b = (button_info *)xmalloc(sizeof(button_info)); + ub->c->buttons[num] = b; + + memset((void *)b, 0, sizeof(*b)); + b->flags = 0; + b->swallow = 0; + b->BWidth = b->BHeight = 1; + b->BPosX = b->BPosY = 0; + b->parent = ub; + b->n = -1; + b->IconWin = 0; + + b->framew = 1; + b->xpad = 2; + b->ypad = 4; + b->w = 1; + b->h = 1; + b->bw = 1; + + return (b); } /** *** MakeContainer() *** Allocs and sets the container-specific fields of a button. **/ -void MakeContainer(button_info *b) +void +MakeContainer(button_info *b) { - b->c=(container_info*)mymalloc(sizeof(container_info)); - b->flags|=b_Container; - b->c->buttons=NULL; - b->c->num_buttons=0; - b->c->num_rows=0; - b->c->num_columns=0; - b->c->allocated_buttons=0; - b->c->xpos=0; - b->c->ypos=0; - if(b->parent != NULL) - { - if (b->parent->c->flags&b_IconBack || b->parent->c->flags&b_IconParent) - b->c->flags=b_IconParent; - else - b->c->flags=0; - } - else /* This applies to the UberButton */ - { - b->c->flags=b_Font|b_Padding|b_Frame|b_Back|b_Fore; - b->c->font_string=strdup("fixed"); - b->c->xpad=2; - b->c->ypad=4; - b->c->back=strdup("#908090"); - b->c->fore=strdup("black"); - b->c->framew=2; - } + b->c = (container_info *)xmalloc(sizeof(container_info)); + b->flags |= b_Container; + b->c->buttons = NULL; + b->c->num_buttons = 0; + b->c->num_rows = 0; + b->c->num_columns = 0; + b->c->allocated_buttons = 0; + b->c->xpos = 0; + b->c->ypos = 0; + if (b->parent != NULL) { + if (b->parent->c->flags & b_IconBack || + b->parent->c->flags & b_IconParent) + b->c->flags = b_IconParent; + else + b->c->flags = 0; + } else /* This applies to the UberButton */ { + b->c->flags = b_Font | b_Padding | b_Frame | b_Back | b_Fore; + b->c->font_string = strdup("fixed"); + b->c->xpad = 2; + b->c->ypad = 4; + b->c->back = strdup("#908090"); + b->c->fore = strdup("black"); + b->c->framew = 2; + } } /* -------------------------- button administration ------------------------ */ @@ -381,114 +387,112 @@ void MakeContainer(button_info *b) *** NumberButtons() *** Prepare the n fields in each button **/ -void NumberButtons(button_info *b) +void +NumberButtons(button_info *b) { - int i=-1; - while(++ic->num_buttons) - if(b->c->buttons[i]) - { - b->c->buttons[i]->n=i; - if(b->c->buttons[i]->flags&b_Container) - NumberButtons(b->c->buttons[i]); - } + int i = -1; + while (++i < b->c->num_buttons) + if (b->c->buttons[i]) { + b->c->buttons[i]->n = i; + if (b->c->buttons[i]->flags & b_Container) + NumberButtons(b->c->buttons[i]); + } } /** *** PlaceAndExpandButton() *** Places a button in it's container and claims all needed slots. - **/ -char PlaceAndExpandButton(int x, int y, button_info *b, button_info *ub) +**/ +char +PlaceAndExpandButton(int x, int y, button_info *b, button_info *ub) { - int i,j,k; - container_info *c=ub->c; - - i = x+y*c->num_columns; - if (x>=c->num_columns || x<0) - { - fprintf(stderr,"%s: Button out of horizontal range. Quitting.\n",MyName); - fprintf(stderr,"Button=%d num_columns=%d BPosX=%d\n", - i,c->num_columns,b->BPosX); - exit(1); - } - if (y>=c->num_rows || y<0) - { - if (b->flags&b_PosFixed || !(ub->c->flags&b_SizeSmart) || y<0) - { - fprintf(stderr,"%s: Button out of vertical range. Quitting.\n", - MyName); - fprintf(stderr,"Button=%d num_rows=%d BPosY=%d\n", - i,c->num_rows,b->BPosY); - exit(1); + int i, j, k; + container_info *c = ub->c; + + i = x + y * c->num_columns; + if (x >= c->num_columns || x < 0) { + fprintf(stderr, + "%s: Button out of horizontal range. Quitting.\n", MyName); + fprintf(stderr, "Button=%d num_columns=%d BPosX=%d\n", i, + c->num_columns, b->BPosX); + exit(1); } - c->num_rows=y+b->BHeight; - c->num_buttons=c->num_columns*c->num_rows; - alloc_buttonlist(ub,c->num_buttons); - } - if(x+b->BWidth>c->num_columns) - { - fprintf(stderr,"%s: Button too wide. giving up\n",MyName); - fprintf(stderr,"Button=%d num_columns=%d bwidth=%d w=%d\n", - i,c->num_columns,b->BWidth,x); - b->BWidth = c->num_columns-x; - } - if(y+b->BHeight>c->num_rows) - { - if (c->flags&b_SizeSmart) - { - c->num_rows=y+b->BHeight; - c->num_buttons=c->num_columns*c->num_rows; - alloc_buttonlist(ub,c->num_buttons); + if (y >= c->num_rows || y < 0) { + if (b->flags & b_PosFixed || !(ub->c->flags & b_SizeSmart) || + y < 0) { + fprintf(stderr, + "%s: Button out of vertical range. Quitting.\n", + MyName); + fprintf(stderr, "Button=%d num_rows=%d BPosY=%d\n", i, + c->num_rows, b->BPosY); + exit(1); + } + c->num_rows = y + b->BHeight; + c->num_buttons = c->num_columns * c->num_rows; + alloc_buttonlist(ub, c->num_buttons); + } + if (x + b->BWidth > c->num_columns) { + fprintf(stderr, "%s: Button too wide. giving up\n", MyName); + fprintf(stderr, "Button=%d num_columns=%d bwidth=%d w=%d\n", i, + c->num_columns, b->BWidth, x); + b->BWidth = c->num_columns - x; } - else - { - fprintf(stderr,"%s: Button too tall. Giving up\n",MyName); - fprintf(stderr,"Button=%d num_rows=%d bheight=%d h=%d\n", - i,c->num_rows,b->BHeight,y); - b->BHeight = c->num_rows-y; + if (y + b->BHeight > c->num_rows) { + if (c->flags & b_SizeSmart) { + c->num_rows = y + b->BHeight; + c->num_buttons = c->num_columns * c->num_rows; + alloc_buttonlist(ub, c->num_buttons); + } else { + fprintf( + stderr, "%s: Button too tall. Giving up\n", MyName); + fprintf(stderr, + "Button=%d num_rows=%d bheight=%d h=%d\n", i, + c->num_rows, b->BHeight, y); + b->BHeight = c->num_rows - y; + } } - } - - /* check if buttons are free */ - for(k=0;kBHeight;k++) - for(j=0;jBWidth;j++) - if (c->buttons[i+j+k*c->num_columns]) - return 1; - /* claim all buttons */ - for(k=0;kBHeight;k++) - for(j=0;jBWidth;j++) - c->buttons[i+j+k*c->num_columns] = b; - b->BPosX = x; - b->BPosY = y; - return 0; + + /* check if buttons are free */ + for (k = 0; k < b->BHeight; k++) + for (j = 0; j < b->BWidth; j++) + if (c->buttons[i + j + k * c->num_columns]) + return 1; + /* claim all buttons */ + for (k = 0; k < b->BHeight; k++) + for (j = 0; j < b->BWidth; j++) + c->buttons[i + j + k * c->num_columns] = b; + b->BPosX = x; + b->BPosY = y; + return 0; } /** *** ShrinkButton() *** Frees all but the upper left slot a button uses in it's container. - **/ -void ShrinkButton(button_info *b, container_info *c) +**/ +void +ShrinkButton(button_info *b, container_info *c) { - int i,j,k,l; - - if (!b) - { - fprintf(stderr,"error: shrink1: button is empty but shouldn't\n"); - exit(1); - } - i = b->BPosX+b->BPosY*c->num_columns; - /* free all buttons but the upper left corner */ - for(k=0;kBHeight;k++) - for(j=0;jBWidth;j++) - if(j||k) - { - l = i+j+k*c->num_columns; - if (c->buttons[l] != b) - { - fprintf(stderr,"error: shrink2: button was stolen\n"); - exit(1); - } - c->buttons[l] = NULL; + int i, j, k, l; + + if (!b) { + fprintf( + stderr, "error: shrink1: button is empty but shouldn't\n"); + exit(1); } + i = b->BPosX + b->BPosY * c->num_columns; + /* free all buttons but the upper left corner */ + for (k = 0; k < b->BHeight; k++) + for (j = 0; j < b->BWidth; j++) + if (j || k) { + l = i + j + k * c->num_columns; + if (c->buttons[l] != b) { + fprintf(stderr, "error: shrink2: " + "button was stolen\n"); + exit(1); + } + c->buttons[l] = NULL; + } } /** @@ -496,129 +500,139 @@ void ShrinkButton(button_info *b, container_info *c) *** Orders and sizes the buttons in the UberButton, corrects num_rows and *** num_columns in containers. **/ -void ShuffleButtons(button_info *ub) +void +ShuffleButtons(button_info *ub) { - int i,actual_buttons_used; - int next_button_x, next_button_y, num_items; - button_info *b; - button_info **local_buttons; - container_info *c=ub->c; - - /* make local copy of buttons in ub */ - num_items = c->num_buttons; - local_buttons=(button_info**)mymalloc(sizeof(button_info)*num_items); - for(i=0;ibuttons[i]; - c->buttons[i] = NULL; - } - - /* Allow for multi-width/height buttons */ - actual_buttons_used = 0; - for(i=0;iBWidth*local_buttons[i]->BHeight; - - if (!(c->flags&b_SizeFixed)||!(c->num_rows)||!(c->num_columns)) - { - /* Size and create the window */ - if(c->num_rows==0 && c->num_columns==0) - c->num_rows=2; - if(c->num_columns==0) - c->num_columns=1+(actual_buttons_used-1)/c->num_rows; - if(c->num_rows==0) - c->num_rows=1+(actual_buttons_used-1)/c->num_columns; - while(c->num_rows * c->num_columns < actual_buttons_used) - c->num_columns++; - if (!(c->flags&b_SizeFixed)) - { - while(c->num_rows*c->num_columns >= actual_buttons_used + c->num_columns) - c->num_rows--; + int i, actual_buttons_used; + int next_button_x, next_button_y, num_items; + button_info *b; + button_info **local_buttons; + container_info *c = ub->c; + + /* make local copy of buttons in ub */ + num_items = c->num_buttons; + local_buttons = + (button_info **)xmalloc(sizeof(button_info) * num_items); + for (i = 0; i < num_items; i++) { + local_buttons[i] = c->buttons[i]; + c->buttons[i] = NULL; + } + + /* Allow for multi-width/height buttons */ + actual_buttons_used = 0; + for (i = 0; i < num_items; i++) + actual_buttons_used += + local_buttons[i]->BWidth * local_buttons[i]->BHeight; + + if (!(c->flags & b_SizeFixed) || !(c->num_rows) || !(c->num_columns)) { + /* Size and create the window */ + if (c->num_rows == 0 && c->num_columns == 0) + c->num_rows = 2; + if (c->num_columns == 0) + c->num_columns = + 1 + (actual_buttons_used - 1) / c->num_rows; + if (c->num_rows == 0) + c->num_rows = + 1 + (actual_buttons_used - 1) / c->num_columns; + while (c->num_rows * c->num_columns < actual_buttons_used) + c->num_columns++; + if (!(c->flags & b_SizeFixed)) { + while (c->num_rows * c->num_columns >= + actual_buttons_used + c->num_columns) + c->num_rows--; + } + } + + if (c->flags & b_SizeSmart) { + /* Set rows/columns to at least the height/width of largest + * button */ + for (i = 0; i < num_items; i++) { + b = local_buttons[i]; + if (c->num_rows < b->BHeight) + c->num_rows = b->BHeight; + if (c->num_columns < b->BWidth) + c->num_columns = b->BWidth; + if (b->flags & b_PosFixed && + c->num_columns < b->BWidth + b->BPosX) + c->num_columns = b->BWidth + b->BPosX; + if (b->flags & b_PosFixed && + c->num_columns < b->BWidth - b->BPosX) + c->num_columns = b->BWidth - b->BPosX; + if (b->flags & b_PosFixed && + c->num_rows < b->BHeight + b->BPosY) + c->num_rows = b->BHeight + b->BPosY; + if (b->flags & b_PosFixed && + c->num_rows < b->BHeight - b->BPosY) + c->num_rows = b->BHeight - b->BPosY; + } } - } - - if (c->flags&b_SizeSmart) - { - /* Set rows/columns to at least the height/width of largest button */ - for(i=0;inum_rowsBHeight) c->num_rows=b->BHeight; - if (c->num_columnsBWidth) c->num_columns=b->BWidth; - if (b->flags&b_PosFixed && c->num_columnsBWidth+b->BPosX) - c->num_columns=b->BWidth+b->BPosX; - if (b->flags&b_PosFixed && c->num_columnsBWidth-b->BPosX) - c->num_columns=b->BWidth-b->BPosX; - if (b->flags&b_PosFixed && c->num_rowsBHeight+b->BPosY) - c->num_rows=b->BHeight+b->BPosY; - if (b->flags&b_PosFixed && c->num_rowsBHeight-b->BPosY) - c->num_rows=b->BHeight-b->BPosY; + + /* this was buggy before */ + c->num_buttons = c->num_rows * c->num_columns; + alloc_buttonlist(ub, c->num_buttons); + + /* Shuffle subcontainers */ + for (i = 0; i < num_items; i++) { + b = local_buttons[i]; + /* Shuffle subcontainers recursively */ + if (b && b->flags & b_Container) + ShuffleButtons(b); } - } - - /* this was buggy before */ - c->num_buttons = c->num_rows*c->num_columns; - alloc_buttonlist(ub,c->num_buttons); - - /* Shuffle subcontainers */ - for(i=0;iflags&b_Container) - ShuffleButtons(b); - } - - /* Place fixed buttons as given in BPosX and BPosY */ - for(i=0;iflags&b_PosFixed)) continue; - /* recalculate position for negative offsets */ - if (b->BPosX<0) b->BPosX=b->BPosX+c->num_columns-b->BWidth+1; - if (b->BPosY<0) b->BPosY=b->BPosY+c->num_rows-b->BHeight+1; - /* Move button if position given by user */ - if (PlaceAndExpandButton(b->BPosX,b->BPosY,b,ub)) - { - fprintf(stderr, "%s: Overlapping fixed buttons. Quitting.\n",MyName); - fprintf(stderr, "Button=%d, x=%d, y=%d\n", i,b->BPosX,b->BPosY); - exit(1); + + /* Place fixed buttons as given in BPosX and BPosY */ + for (i = 0; i < num_items; i++) { + b = local_buttons[i]; + if (!(b->flags & b_PosFixed)) + continue; + /* recalculate position for negative offsets */ + if (b->BPosX < 0) + b->BPosX = b->BPosX + c->num_columns - b->BWidth + 1; + if (b->BPosY < 0) + b->BPosY = b->BPosY + c->num_rows - b->BHeight + 1; + /* Move button if position given by user */ + if (PlaceAndExpandButton(b->BPosX, b->BPosY, b, ub)) { + fprintf(stderr, + "%s: Overlapping fixed buttons. Quitting.\n", + MyName); + fprintf(stderr, "Button=%d, x=%d, y=%d\n", i, b->BPosX, + b->BPosY); + exit(1); + } } - } - - /* place floating buttons dynamically */ - next_button_x = next_button_y = 0; - for(i=0;iflags&b_PosFixed) continue; - - if (next_button_x+b->BWidth>c->num_columns) - { - next_button_y++; - next_button_x=0; - } - /* Search for next free position to accomodate button */ - while (PlaceAndExpandButton(next_button_x,next_button_y,b,ub)) - { - next_button_x++; - if (next_button_x+b->BWidth>c->num_columns) - { - next_button_y++; - next_button_x=0; - if (next_button_y>=c->num_rows) - { - /* could not place button */ - fprintf(stderr,"%s: Button confusion! Quitting\n", MyName); - exit(1); + + /* place floating buttons dynamically */ + next_button_x = next_button_y = 0; + for (i = 0; i < num_items; i++) { + b = local_buttons[i]; + if (b->flags & b_PosFixed) + continue; + + if (next_button_x + b->BWidth > c->num_columns) { + next_button_y++; + next_button_x = 0; + } + /* Search for next free position to accomodate button */ + while (PlaceAndExpandButton(next_button_x, next_button_y, b, + ub)) { + next_button_x++; + if (next_button_x + b->BWidth > c->num_columns) { + next_button_y++; + next_button_x = 0; + if (next_button_y >= c->num_rows) { + /* could not place button */ + fprintf(stderr, + "%s: Button confusion! Quitting\n", + MyName); + exit(1); + } + } } - } } - } - /* shrink buttons in Container */ - for(i=0;ic->num_buttons && !(*ub)->c->buttons[*i]) - (*i)++; - /* End of contained buttons */ - if((*i)>=(*ub)->c->num_buttons) - { - *b=*ub; - *ub=(*b)->parent; - /* End of the world as we know it */ - if(!(*ub)) - { - *b=NULL; - return *b; + /* Get next button */ + (*i)++; + /* Skip fake buttons */ + while ((*i) < (*ub)->c->num_buttons && !(*ub)->c->buttons[*i]) + (*i)++; + /* End of contained buttons */ + if ((*i) >= (*ub)->c->num_buttons) { + *b = *ub; + *ub = (*b)->parent; + /* End of the world as we know it */ + if (!(*ub)) { + *b = NULL; + return *b; + } + *i = (*b)->n; + if ((*i) >= (*ub)->c->num_buttons) { + fprintf(stderr, + "%s: BUG: Couldn't return to uberbutton\n", MyName); + exit(2); + } + NextButton(ub, b, i, all); + return *b; } - *i=(*b)->n; - if((*i)>=(*ub)->c->num_buttons) - { - fprintf(stderr,"%s: BUG: Couldn't return to uberbutton\n",MyName); - exit(2); + *b = (*ub)->c->buttons[*i]; + + /* Found new container */ + if ((*b)->flags & b_Container) { + *i = -1; + *ub = *b; + if (!all) + NextButton(ub, b, i, all); + return *b; } - NextButton(ub,b,i,all); - return *b; - } - *b=(*ub)->c->buttons[*i]; - - /* Found new container */ - if((*b)->flags & b_Container) - { - *i=-1; - *ub=*b; - if(!all) - NextButton(ub,b,i,all); - return *b; - } - return *b; + return *b; } /* --------------------------- button navigation --------------------------- */ @@ -678,50 +690,54 @@ button_info *NextButton(button_info **ub,button_info **b,int *i,int all) *** Function that finds out which button a given position belongs to. *** Returns -1 is not part of any, button if a proper button. **/ -int button_belongs_to(button_info *ub,int button) +int +button_belongs_to(button_info *ub, int button) { - int x,y,xx,yy; - button_info *b; - if(!ub || button<0 || button>ub->c->num_buttons) - return -1; - if(ub->c->buttons[button]) - return button; - yy=button/ub->c->num_columns; - xx=button%ub->c->num_columns; - for(y=yy;y>=0;y--) - for(x=xx;x>=0;x--) - { - b=ub->c->buttons[x+y*ub->c->num_columns]; - if(b && (x+b->BWidth > xx) && (y+b->BHeight > yy)) - { - return x+y*ub->c->num_columns; - } - } - return -1; + int x, y, xx, yy; + button_info *b; + if (!ub || button < 0 || button > ub->c->num_buttons) + return -1; + if (ub->c->buttons[button]) + return button; + yy = button / ub->c->num_columns; + xx = button % ub->c->num_columns; + for (y = yy; y >= 0; y--) + for (x = xx; x >= 0; x--) { + b = ub->c->buttons[x + y * ub->c->num_columns]; + if (b && (x + b->BWidth > xx) && + (y + b->BHeight > yy)) { + return x + y * ub->c->num_columns; + } + } + return -1; } /** *** select_button() *** Given (x,y) and uberbutton, returns pointer to referred button, or NULL **/ -button_info *select_button(button_info *ub,int x,int y) +button_info * +select_button(button_info *ub, int x, int y) { - int i; - button_info *b; - if(!(ub->flags&b_Container)) - return ub; - - x-=buttonXPad(ub)+buttonFrame(ub); - y-=buttonYPad(ub)+buttonFrame(ub); - - if(x >= ub->c->ButtonWidth * ub->c->num_columns || x<0 || - y >= ub->c->ButtonHeight * ub->c->num_rows || y<0) - return ub; - - i=x/ub->c->ButtonWidth + (y/ub->c->ButtonHeight)*ub->c->num_columns; - i=button_belongs_to(ub,i); - if(i==-1)return ub; - b=ub->c->buttons[i]; - return select_button(b,x-(i%ub->c->num_columns)*ub->c->ButtonWidth, - y-(i/ub->c->num_columns)*ub->c->ButtonHeight); + int i; + button_info *b; + if (!(ub->flags & b_Container)) + return ub; + + x -= buttonXPad(ub) + buttonFrame(ub); + y -= buttonYPad(ub) + buttonFrame(ub); + + if (x >= ub->c->ButtonWidth * ub->c->num_columns || x < 0 || + y >= ub->c->ButtonHeight * ub->c->num_rows || y < 0) + return ub; + + i = x / ub->c->ButtonWidth + + (y / ub->c->ButtonHeight) * ub->c->num_columns; + i = button_belongs_to(ub, i); + if (i == -1) + return ub; + b = ub->c->buttons[i]; + return select_button(b, + x - (i % ub->c->num_columns) * ub->c->ButtonWidth, + y - (i / ub->c->num_columns) * ub->c->ButtonHeight); } Index: fvwm/modules/FvwmButtons/button.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/button.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/button.h --- fvwm/modules/FvwmButtons/button.h +++ fvwm/modules/FvwmButtons/button.h @@ -14,51 +14,50 @@ /* --------------------------- button information -------------------------- */ -#define buttonXPos(b,i) \ - ((b)->parent->c->xpos + \ - ((i)%(b)->parent->c->num_columns)*((b)->parent->c->ButtonWidth)) -#define buttonYPos(b,i) \ - ((b)->parent->c->ypos + \ - ((i)/(b)->parent->c->num_columns)*((b)->parent->c->ButtonHeight)) -#define buttonWidth(b) \ - ((b)->BWidth*(b)->parent->c->ButtonWidth) -#define buttonHeight(b) \ - ((b)->BHeight*(b)->parent->c->ButtonHeight) - -#define buttonSwallowCount(b) \ - (((b)->flags&b_Swallow)?((b)->swallow&b_Count):0) - -void buttonInfo(button_info*,int *x,int *y,int *padx,int *pady,int *frame); -void GetInternalSize(button_info*,int*,int*,int*,int*); +#define buttonXPos(b, i) \ + ((b)->parent->c->xpos + ((i) % (b)->parent->c->num_columns) * \ + ((b)->parent->c->ButtonWidth)) +#define buttonYPos(b, i) \ + ((b)->parent->c->ypos + ((i) / (b)->parent->c->num_columns) * \ + ((b)->parent->c->ButtonHeight)) +#define buttonWidth(b) ((b)->BWidth * (b)->parent->c->ButtonWidth) +#define buttonHeight(b) ((b)->BHeight * (b)->parent->c->ButtonHeight) + +#define buttonSwallowCount(b) \ + (((b)->flags & b_Swallow) ? ((b)->swallow & b_Count) : 0) + +void buttonInfo( + button_info *, int *x, int *y, int *padx, int *pady, int *frame); +void GetInternalSize(button_info *, int *, int *, int *, int *); #define buttonFrame(b) abs(buttonFrameSigned(b)) -int buttonFrameSigned(button_info*); -int buttonXPad(button_info*); -int buttonYPad(button_info*); -XFontStruct *buttonFont(button_info*); -Pixel buttonFore(button_info*); -Pixel buttonBack(button_info*); -Pixel buttonHilite(button_info*); -Pixel buttonShadow(button_info*); -byte buttonSwallow(button_info*); -byte buttonJustify(button_info*); +int buttonFrameSigned(button_info *); +int buttonXPad(button_info *); +int buttonYPad(button_info *); +XFontStruct *buttonFont(button_info *); +Pixel buttonFore(button_info *); +Pixel buttonBack(button_info *); +Pixel buttonHilite(button_info *); +Pixel buttonShadow(button_info *); +byte buttonSwallow(button_info *); +byte buttonJustify(button_info *); #define buttonNum(b) ((b)->n) /* ---------------------------- button creation ---------------------------- */ -void alloc_buttonlist(button_info*,int); -button_info *alloc_button(button_info*,int); -void MakeContainer(button_info*); +void alloc_buttonlist(button_info *, int); +button_info *alloc_button(button_info *, int); +void MakeContainer(button_info *); /* ------------------------- button administration ------------------------- */ -void NumberButtons(button_info*); -void ShuffleButtons(button_info*); +void NumberButtons(button_info *); +void ShuffleButtons(button_info *); /* ---------------------------- button iterator ---------------------------- */ -button_info *NextButton(button_info**,button_info**,int*,int); +button_info *NextButton(button_info **, button_info **, int *, int); /* --------------------------- button navigation --------------------------- */ -int button_belongs_to(button_info*,int); -button_info *select_button(button_info*,int,int); +int button_belongs_to(button_info *, int); +button_info *select_button(button_info *, int, int); Index: fvwm/modules/FvwmButtons/draw.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/draw.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/draw.c --- fvwm/modules/FvwmButtons/draw.c +++ fvwm/modules/FvwmButtons/draw.c @@ -16,26 +16,23 @@ #include "config.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include -#include -#include -#include - +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include #include "FvwmButtons.h" -#include "misc.h" /* ConstrainSize() */ -#include "icons.h" /* ConfigureIconWindow() */ #include "button.h" #include "draw.h" +#include "icons.h" /* ConfigureIconWindow() */ +#include "misc.h" /* ConstrainSize() */ /* ---------------- Functions that design and draw buttons ----------------- */ @@ -43,134 +40,156 @@ *** RelieveWindow() *** Draws the relief pattern around a window. **/ -void RelieveWindow(Window wn,int width,int x,int y,int w,int h,Pixel relief, - Pixel shadow,int rev) +void +RelieveWindow(Window wn, int width, int x, int y, int w, int h, Pixel relief, + Pixel shadow, int rev) { - XSegment seg[4]; - unsigned long gcm=0; - XGCValues gcv; - Pixel p; - int i,j; - - if(!width) - return; - if(width<0) - { - width=-width; - p=relief;relief=shadow;shadow=p; - } - if(rev) - { - p=relief;relief=shadow;shadow=p; - } - - gcm=GCForeground; - gcv.foreground=relief; - XChangeGC(Dpy,NormalGC,gcm,&gcv); - - for(j=0;j1 && h>1 ;j++,w-=2,h-=2,x+=1,y+=1) - { - i=0; - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = x+w-1; seg[i++].y2 = y; - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = x; seg[i++].y2 = y+h-1; - XDrawSegments(Dpy,wn,NormalGC,seg,i); - } - - w+=width*2;h+=width*2;x-=width;y-=width; - - gcm=GCForeground; - gcv.foreground=shadow; - XChangeGC(Dpy,NormalGC,gcm,&gcv); - - for(j=0;j1 && h>1 ;j++,w-=2,h-=2,x+=1,y+=1) - { - i=0; - seg[i].x1 = x+1; seg[i].y1 = y+h-1; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - seg[i].x1 = x+w-1; seg[i].y1 = y+1; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - XDrawSegments(Dpy,wn,NormalGC,seg,i); - } + XSegment seg[4]; + unsigned long gcm = 0; + XGCValues gcv; + Pixel p; + int i, j; + + if (!width) + return; + if (width < 0) { + width = -width; + p = relief; + relief = shadow; + shadow = p; + } + if (rev) { + p = relief; + relief = shadow; + shadow = p; + } + + gcm = GCForeground; + gcv.foreground = relief; + XChangeGC(Dpy, NormalGC, gcm, &gcv); + + for (j = 0; j < width && w > 1 && h > 1; + j++, w -= 2, h -= 2, x += 1, y += 1) { + i = 0; + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y; + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = x; + seg[i++].y2 = y + h - 1; + XDrawSegments(Dpy, wn, NormalGC, seg, i); + } + + w += width * 2; + h += width * 2; + x -= width; + y -= width; + + gcm = GCForeground; + gcv.foreground = shadow; + XChangeGC(Dpy, NormalGC, gcm, &gcv); + + for (j = 0; j < width && w > 1 && h > 1; + j++, w -= 2, h -= 2, x += 1, y += 1) { + i = 0; + seg[i].x1 = x + 1; + seg[i].y1 = y + h - 1; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + seg[i].x1 = x + w - 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + XDrawSegments(Dpy, wn, NormalGC, seg, i); + } } /** *** MakeButton() *** To position subwindows in a button: icons and swallowed windows. **/ -void MakeButton(button_info *b) +void +MakeButton(button_info *b) { - /* This is resposible for drawing the contents of a button, placing the - icon and/or swallowed item in the correct position inside potential - padding or frame. - */ - int ih,iw,ix,iy; - XFontStruct *font; - - if(!b) - { - fprintf(stderr,"%s: BUG: DrawButton called with NULL pointer\n",MyName); - exit(2); - } - if(b->flags&b_Container) - { - fprintf(stderr,"%s: BUG: DrawButton called with container\n",MyName); - exit(2); - } - - if(!(b->flags&b_Icon) && (buttonSwallowCount(b)<3)) - return; - - /* Check if parent container has an icon as background */ - if (b->parent->c->flags&b_IconBack || b->parent->c->flags&b_IconParent) - b->flags|=b_IconParent; - - font = buttonFont(b); - - GetInternalSize(b,&ix,&iy,&iw,&ih); - - /* At this point iw,ih,ix and iy should be correct. Now all we have to do is - place title and iconwin in their proper positions */ - - /* For now, use the old routine in icons.h for buttons with icons */ - if(b->flags&b_Icon) - ConfigureIconWindow(b); - - /* For now, hardcoded window centered, title bottom centered, below window */ - else if(buttonSwallowCount(b)==3) - { - long supplied; - if(!b->IconWin) - { - fprintf(stderr,"%s: BUG: Swallowed window has no IconWin\n",MyName); - exit(2); + /* This is resposible for drawing the contents of a button, placing the + icon and/or swallowed item in the correct position inside potential + padding or frame. + */ + int ih, iw, ix, iy; + XFontStruct *font; + + if (!b) { + fprintf(stderr, + "%s: BUG: DrawButton called with NULL pointer\n", MyName); + exit(2); + } + if (b->flags & b_Container) { + fprintf(stderr, "%s: BUG: DrawButton called with container\n", + MyName); + exit(2); } - if(b->flags&b_Title && font && !(buttonJustify(b)&b_Horizontal)) - ih -= font->ascent+font->descent; - - b->icon_w=iw; - b->icon_h=ih; - - if(iw>0 && ih>0) - { - if(!(buttonSwallow(b)&b_NoHints)) - { - if(!XGetWMNormalHints(Dpy,b->IconWin,b->hints,&supplied)) - b->hints->flags=0; - ConstrainSize(b->hints,&b->icon_w,&b->icon_h); - } - if (b->flags & b_Right) - ix += iw-b->icon_w; - else if (!(b->flags & b_Left)) - ix += (iw-b->icon_w)/2; - XMoveResizeWindow(Dpy,b->IconWin,ix,iy+(ih-b->icon_h)/2, - b->icon_w,b->icon_h); + if (!(b->flags & b_Icon) && (buttonSwallowCount(b) < 3)) + return; + + /* Check if parent container has an icon as background */ + if (b->parent->c->flags & b_IconBack || + b->parent->c->flags & b_IconParent) + b->flags |= b_IconParent; + + font = buttonFont(b); + + GetInternalSize(b, &ix, &iy, &iw, &ih); + + /* At this point iw,ih,ix and iy should be correct. Now all we have to + do is place title and iconwin in their proper positions */ + + /* For now, use the old routine in icons.h for buttons with icons */ + if (b->flags & b_Icon) + ConfigureIconWindow(b); + + /* For now, hardcoded window centered, title bottom centered, below + * window */ + else if (buttonSwallowCount(b) == 3) { + long supplied; + if (!b->IconWin) { + fprintf(stderr, + "%s: BUG: Swallowed window has no IconWin\n", + MyName); + exit(2); + } + + if (b->flags & b_Title && font && + !(buttonJustify(b) & b_Horizontal)) + ih -= font->ascent + font->descent; + + b->icon_w = iw; + b->icon_h = ih; + + if (iw > 8 && ih > 8) { + if (!(buttonSwallow(b) & b_NoHints)) { + if (!XGetWMNormalHints( + Dpy, b->IconWin, b->hints, &supplied)) + b->hints->flags = 0; + ConstrainSize(b->hints, &b->icon_w, &b->icon_h); + if (b->icon_w < 1) + b->icon_w = 1; + if (b->icon_h < 1) + b->icon_h = 1; + } + b->icon_w = max(b->icon_w, 8); + b->icon_h = max(b->icon_h, 8); + if (b->flags & b_Right) + ix += iw - b->icon_w; + else if (!(b->flags & b_Left)) + ix += (iw - b->icon_w) / 2; + XMoveResizeWindow(Dpy, b->IconWin, ix, + iy + (ih - b->icon_h) / 2, b->icon_w, b->icon_h); + } else + XMoveWindow(Dpy, b->IconWin, 2000, 2000); } - else - XMoveWindow(Dpy,b->IconWin,2000,2000); - } } /** @@ -178,163 +197,167 @@ void MakeButton(button_info *b) *** Writes out title, if any, and displays the bevel right, by calling *** RelieveWindow. If clean is nonzero, also clears background. **/ -void RedrawButton(button_info *b,int clean) +void +RedrawButton(button_info *b, int clean) { - int i,j,k,BH,BW; - int f,x,y,px,py; - int ix,iy,iw,ih; - XFontStruct *font=buttonFont(b); - XGCValues gcv; - unsigned long gcm=0; - int rev=0; - - BW = buttonWidth(b); - BH = buttonHeight(b); - buttonInfo(b,&x,&y,&px,&py,&f); - GetInternalSize(b,&ix,&iy,&iw,&ih); - - /* This probably isn't the place for this, but it seems to work here and not - elsewhere, so... */ - if((buttonSwallowCount(b)==3) && b->IconWin!=None) - XSetWindowBorderWidth(Dpy,b->IconWin,0); - - /* ----------------------------------------------------------------------- */ - - if(b->flags&b_Hangon || b==CurrentButton) /* Hanging or held down by user */ - rev=1; - if(b->flags&b_Action) /* If this is a Desk button that takes you to here.. */ - { - int n=0; - while(n<4 && (!b->action[n] || strncasecmp(b->action[n],"Desk",4))) - n++; - if(n<4) - { - k=sscanf(&b->action[n][4],"%d%d",&i,&j); - if(k==2 && i==0 && j==new_desk) - rev=1; + int i, j, k, BH, BW; + int f, x, y, px, py; + int ix, iy, iw, ih; + XFontStruct *font = buttonFont(b); + XGCValues gcv; + unsigned long gcm = 0; + int rev = 0; + + BW = buttonWidth(b); + BH = buttonHeight(b); + buttonInfo(b, &x, &y, &px, &py, &f); + GetInternalSize(b, &ix, &iy, &iw, &ih); + + /* This probably isn't the place for this, but it seems to work here and + not elsewhere, so... */ + if ((buttonSwallowCount(b) == 3) && b->IconWin != None) + XSetWindowBorderWidth(Dpy, b->IconWin, 0); + + /* ----------------------------------------------------------------------- + */ + + if (b->flags & b_Hangon || + b == CurrentButton) /* Hanging or held down by user */ + rev = 1; + if (b->flags & + b_Action) { /* If this is a Desk button that takes you to here.. */ + int n = 0; + while (n < 4 && + (!b->action[n] || strncasecmp(b->action[n], "Desk", 4))) + n++; + if (n < 4) { + k = sscanf(&b->action[n][4], "%d%d", &i, &j); + if (k == 2 && i == 0 && j == new_desk) + rev = 1; + } } - } - RelieveWindow(MyWindow,f,x,y,BW,BH,buttonHilite(b),buttonShadow(b),rev); - - /* ----------------------------------------------------------------------- */ - - f=abs(f); - - if(clean && BW>2*f && BH>2*f) - { - gcm = GCForeground; - gcv.foreground=buttonBack(b); - XChangeGC(Dpy,NormalGC,gcm,&gcv); - - if(b->flags&b_Container) - { - int x1=x+f,y1=y+f; - int w1=px,h1=py,w2=w1,h2=h1; - int w=BW-2*f,h=BH-2*f; - w2+=iw - b->c->num_columns*b->c->ButtonWidth; - h2+=ih - b->c->num_rows*b->c->ButtonHeight; - - if(w1)XFillRectangle(Dpy,MyWindow,NormalGC,x1,y1,w1,h); - if(w2)XFillRectangle(Dpy,MyWindow,NormalGC,x1+w-w2,y1,w2,h); - if(h1)XFillRectangle(Dpy,MyWindow,NormalGC,x1,y1,w,h1); - if(h2)XFillRectangle(Dpy,MyWindow,NormalGC,x1,y1+h-h2,w,h2); + RelieveWindow( + MyWindow, f, x, y, BW, BH, buttonHilite(b), buttonShadow(b), rev); + + /* ----------------------------------------------------------------------- + */ + + f = abs(f); + + if (clean && BW > 2 * f && BH > 2 * f) { + gcm = GCForeground; + gcv.foreground = buttonBack(b); + XChangeGC(Dpy, NormalGC, gcm, &gcv); + + if (b->flags & b_Container) { + int x1 = x + f, y1 = y + f; + int w1 = px, h1 = py, w2 = w1, h2 = h1; + int w = BW - 2 * f, h = BH - 2 * f; + w2 += iw - b->c->num_columns * b->c->ButtonWidth; + h2 += ih - b->c->num_rows * b->c->ButtonHeight; + + if (w1) + XFillRectangle( + Dpy, MyWindow, NormalGC, x1, y1, w1, h); + if (w2) + XFillRectangle(Dpy, MyWindow, NormalGC, + x1 + w - w2, y1, w2, h); + if (h1) + XFillRectangle( + Dpy, MyWindow, NormalGC, x1, y1, w, h1); + if (h2) + XFillRectangle(Dpy, MyWindow, NormalGC, x1, + y1 + h - h2, w, h2); + } else if (!(b->flags & b_IconBack) && + !(b->flags & b_IconParent) && + !(b->flags & b_Swallow)) + XFillRectangle(Dpy, MyWindow, NormalGC, x + f, y + f, + BW - 2 * f, BH - 2 * f); + } + + /* ----------------------------------------------------------------------- + */ + + if (b->flags & b_Title && font) { + gcm = GCForeground | GCFont; + gcv.foreground = buttonFore(b); + gcv.font = font->fid; + XChangeGC(Dpy, NormalGC, gcm, &gcv); + DrawTitle(b, MyWindow, NormalGC); } - else if(!(b->flags&b_IconBack) && !(b->flags&b_IconParent) && - !(b->flags&b_Swallow)) - XFillRectangle(Dpy,MyWindow,NormalGC,x+f,y+f,BW-2*f,BH-2*f); - } - - /* ----------------------------------------------------------------------- */ - - if(b->flags&b_Title && font) - { - gcm = GCForeground | GCFont; - gcv.foreground=buttonFore(b); - gcv.font = font->fid; - XChangeGC(Dpy,NormalGC,gcm,&gcv); - DrawTitle(b,MyWindow,NormalGC); - } } /** *** DrawTitle() *** Writes out title. **/ -void DrawTitle(button_info *b,Window win,GC gc) +void +DrawTitle(button_info *b, Window win, GC gc) { - int BH; - int ix,iy,iw,ih; - XFontStruct *font=buttonFont(b); - int justify=buttonJustify(b); - int l,i,xpos; - char *s; - int just=justify&b_TitleHoriz; /* Left, center, right */ - - BH = buttonHeight(b); - - GetInternalSize(b,&ix,&iy,&iw,&ih); - - /* ----------------------------------------------------------------------- */ - - if(!(b->flags&b_Title) || !font) - return; - - /* If a title is to be shown, truncate it until it fits */ - if(justify&b_Horizontal) - { - if(b->flags&b_Icon) - { - ix+=b->icon->width+buttonXPad(b); - iw-=b->icon->width+buttonXPad(b); - } - else if (buttonSwallowCount(b)==3) - { - ix+=b->icon_w+buttonXPad(b); - iw-=b->icon_w+buttonXPad(b); + int BH; + int ix, iy, iw, ih; + XFontStruct *font = buttonFont(b); + int justify = buttonJustify(b); + int l, i, xpos; + char *s; + int just = justify & b_TitleHoriz; /* Left, center, right */ + + BH = buttonHeight(b); + + GetInternalSize(b, &ix, &iy, &iw, &ih); + + /* ----------------------------------------------------------------------- + */ + + if (!(b->flags & b_Title) || !font) + return; + + /* If a title is to be shown, truncate it until it fits */ + if (justify & b_Horizontal) { + if (b->flags & b_Icon) { + ix += b->icon->width + buttonXPad(b); + iw -= b->icon->width + buttonXPad(b); + } else if (buttonSwallowCount(b) == 3) { + ix += b->icon_w + buttonXPad(b); + iw -= b->icon_w + buttonXPad(b); + } } - } - - s=b->title; - l=strlen(s); - i=XTextWidth(font,s,l); - - if(i>iw) - { - if(just==2) - { - while(i>iw && *s) - i=XTextWidth(font,++s,--l); - } - else /* Left or center - cut off its tail */ - { - while(i>iw && l>0) - i=XTextWidth(font,s,--l); - } - } - if(just==0) /* Left */ - xpos=ix; - else if(just==2) /* Right */ - xpos=max(ix,ix+iw-i); - else /* Centered, I guess */ - xpos=ix+(iw-i)/2; - - if(*s && l>0 && BH>=font->descent+font->ascent) /* Clip it somehow? */ - { - /* If there is more than the title, put it at the bottom */ - /* Unless stack flag is set, put it to the right of icon */ - if((b->flags&b_Icon || (buttonSwallowCount(b)==3)) && - !(justify&b_Horizontal)) - { - XDrawString(Dpy,win,gc,xpos, - iy+ih-font->descent,s,l); - /* Shrink the space available for icon/window */ - ih-=font->descent+font->ascent; + + s = b->title; + l = strlen(s); + i = XTextWidth(font, s, l); + + if (i > iw) { + if (just == 2) { + while (i > iw && *s) + i = XTextWidth(font, ++s, --l); + } else /* Left or center - cut off its tail */ { + while (i > iw && l > 0) + i = XTextWidth(font, s, --l); + } } - /* Or else center vertically */ - else - { - XDrawString(Dpy,win,gc,xpos, - iy+(ih+font->ascent-font->descent)/2,s,l); + if (just == 0) /* Left */ + xpos = ix; + else if (just == 2) /* Right */ + xpos = max(ix, ix + iw - i); + else /* Centered, I guess */ + xpos = ix + (iw - i) / 2; + + if (*s && l > 0 && + BH >= font->descent + font->ascent) { /* Clip it somehow? */ + /* If there is more than the title, put it at the bottom */ + /* Unless stack flag is set, put it to the right of icon */ + if ((b->flags & b_Icon || (buttonSwallowCount(b) == 3)) && + !(justify & b_Horizontal)) { + XDrawString( + Dpy, win, gc, xpos, iy + ih - font->descent, s, l); + /* Shrink the space available for icon/window */ + ih -= font->descent + font->ascent; + } + /* Or else center vertically */ + else { + XDrawString(Dpy, win, gc, xpos, + iy + (ih + font->ascent - font->descent) / 2, s, l); + } } - } } Index: fvwm/modules/FvwmButtons/draw.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/draw.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/draw.h --- fvwm/modules/FvwmButtons/draw.h +++ fvwm/modules/FvwmButtons/draw.h @@ -12,8 +12,7 @@ */ -void RelieveWindow(Window,int,int,int,int,int,Pixel,Pixel,int); -void MakeButton(button_info*); -void RedrawButton(button_info*,int); -void DrawTitle(button_info*,Window,GC); - +void RelieveWindow(Window, int, int, int, int, int, Pixel, Pixel, int); +void MakeButton(button_info *); +void RedrawButton(button_info *, int); +void DrawTitle(button_info *, Window, GC); Index: fvwm/modules/FvwmButtons/icons.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/icons.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/icons.c --- fvwm/modules/FvwmButtons/icons.c +++ fvwm/modules/FvwmButtons/icons.c @@ -8,7 +8,7 @@ * Copyright 1993, Robert Nation. No guarantees or warantees or anything * are provided or implied in any way whatsoever. Use this program at your * own risk. Permission to use this program for any purpose is given, - * as long as the copyright is kept intact. + * as long as the copyright is kept intact. */ /*********************************************************************** @@ -17,19 +17,18 @@ * ***********************************************************************/ -#include "config.h" - -#include -#include +#include +#include +#include +#include +#include #include -#include +#include #include +#include +#include -#include -#include -#include -#include -#include +#include "config.h" #ifdef HAVE_FCNTL_H #include @@ -51,159 +50,161 @@ * Creates an Icon Window * ****************************************************************************/ -void CreateIconWindow(button_info *b) +void +CreateIconWindow(button_info *b) { #ifndef NO_ICONS - unsigned long valuemask; /* mask for create windows */ - XSetWindowAttributes attributes; /* attributes for create windows */ - - if(!(b->flags&b_Icon)) - return; - - if(b->IconWin != None) - { - fprintf(stderr,"%s: BUG: Iconwindow already created for 0x%lx!\n", - MyName,(unsigned long)b); - exit(2); - } - - attributes.background_pixel = buttonBack(b); - attributes.event_mask = ExposureMask; - valuemask = CWEventMask | CWBackPixel; - - if(b->icon->width<1 || b->icon->height<1) - { - fprintf(stderr,"%s: BUG: Illegal iconwindow tried created\n",MyName); - exit(2); - } - b->IconWin=XCreateWindow(Dpy,MyWindow,0,0,b->icon->width,b->icon->height, - 0, CopyFromParent, CopyFromParent,CopyFromParent, - valuemask,&attributes); + unsigned long valuemask; /* mask for create windows */ + XSetWindowAttributes attributes; /* attributes for create windows */ + + if (!(b->flags & b_Icon)) + return; + + if (b->IconWin != None) { + fprintf(stderr, + "%s: BUG: Iconwindow already created for 0x%lx!\n", MyName, + (unsigned long)b); + exit(2); + } + + attributes.background_pixel = buttonBack(b); + attributes.event_mask = ExposureMask; + valuemask = CWEventMask | CWBackPixel; + + if (b->icon->width < 1 || b->icon->height < 1) { + fprintf(stderr, "%s: BUG: Illegal iconwindow tried created\n", + MyName); + exit(2); + } + b->IconWin = XCreateWindow(Dpy, MyWindow, 0, 0, b->icon->width, + b->icon->height, 0, CopyFromParent, CopyFromParent, CopyFromParent, + valuemask, &attributes); #ifdef XPM #ifdef SHAPE - if (b->icon->mask!=None) - XShapeCombineMask(Dpy,b->IconWin,ShapeBounding,0,0, - b->icon->mask,ShapeSet); + if (b->icon->mask != None) + XShapeCombineMask(Dpy, b->IconWin, ShapeBounding, 0, 0, + b->icon->mask, ShapeSet); #endif #endif - if(b->icon->depth==0) - { - XGCValues gcv; - unsigned long gcm=0; - Pixmap temp; - - gcm = GCForeground | GCBackground; - gcv.background=buttonBack(b); - gcv.foreground=buttonFore(b); - XChangeGC(Dpy,NormalGC,gcm,&gcv); - + if (b->icon->depth == 0) { + XGCValues gcv; + unsigned long gcm = 0; + Pixmap temp; + + gcm = GCForeground | GCBackground; + gcv.background = buttonBack(b); + gcv.foreground = buttonFore(b); + XChangeGC(Dpy, NormalGC, gcm, &gcv); + #ifdef SHAPE - XShapeCombineMask(Dpy,b->IconWin,ShapeBounding,0,0, - b->icon->picture,ShapeSet); + XShapeCombineMask(Dpy, b->IconWin, ShapeBounding, 0, 0, + b->icon->picture, ShapeSet); #endif - - temp = XCreatePixmap(Dpy,Root,b->icon->width, - b->icon->height,d_depth); - XCopyPlane(Dpy,b->icon->picture,temp,NormalGC, - 0,0,b->icon->width,b->icon->height,0,0,1); - - XSetWindowBackgroundPixmap(Dpy,b->IconWin,temp); - XFreePixmap(Dpy,temp); - /* We won't use the icon pixmap anymore... but we still need it for - width/height etc. so we can't destroy it. */ - } - else - XSetWindowBackgroundPixmap(Dpy,b->IconWin,b->icon->picture); - - return; + + temp = XCreatePixmap( + Dpy, Root, b->icon->width, b->icon->height, d_depth); + XCopyPlane(Dpy, b->icon->picture, temp, NormalGC, 0, 0, + b->icon->width, b->icon->height, 0, 0, 1); + + XSetWindowBackgroundPixmap(Dpy, b->IconWin, temp); + XFreePixmap(Dpy, temp); + /* We won't use the icon pixmap anymore... but we still need it + for width/height etc. so we can't destroy it. */ + } else + XSetWindowBackgroundPixmap(Dpy, b->IconWin, b->icon->picture); + + return; #endif } - /**************************************************************************** * * Combines icon shape masks after a resize * ****************************************************************************/ -void ConfigureIconWindow(button_info *b) +void +ConfigureIconWindow(button_info *b) { #ifndef NO_ICONS - int x,y,w,h; - int xoff,yoff; - int framew,xpad,ypad; - XFontStruct *font; - int BW,BH; - - if(!b || !(b->flags&b_Icon)) - return; - - if(!b->IconWin) - { - fprintf(stderr,"%s: DEBUG: Tried to configure erroneous iconwindow\n", - MyName); - exit(2); - } - - buttonInfo(b,&x,&y,&xpad,&ypad,&framew); - framew=abs(framew); - - font = buttonFont(b); - w = b->icon->width; - h = b->icon->height; - BW = buttonWidth(b); - BH = buttonHeight(b); - - w=min(w,BW-2*(xpad+framew)); - - if(b->flags&b_Title && font && !(buttonJustify(b)&b_Horizontal)) - h=min(h,BH-2*(ypad+framew)-font->ascent-font->descent); - else - h=min(h,BH-2*(ypad+framew)); - - if(w < 1 || h < 1) - { - XMoveResizeWindow(Dpy, b->IconWin, 2000,2000,1,1); - return; /* No need drawing to this */ - } - - if(buttonJustify(b)&b_Horizontal) - xoff=0; - else - xoff=(BW-w)>>1; - - if(b->flags&b_Title && font && !(buttonJustify(b)&b_Horizontal)) - yoff=(BH-(h+font->ascent+font->descent))>>1; - else - yoff=(BH-h)>>1; - - if(xoff < framew+xpad) - xoff = framew+xpad; - if(yoff < framew+ypad) - yoff = framew+ypad; - - x += xoff; - y += yoff; - - XMoveResizeWindow(Dpy, b->IconWin, x,y,w,h); - -/* Doesn't this belong above? -#ifdef XPM -#ifdef SHAPE - if (b->icon->mask!=None) - { - XShapeCombineMask(Dpy,b->IconWin,ShapeBounding,0,0, - b->icon->mask,ShapeSet); - } -#endif -#endif - if(b->icon->depth==0) - { - PixmapFromBitmap(b); - } - XSetWindowBackgroundPixmap(Dpy,b->IconWin,b->icon->picture); -*/ + int x, y, w, h; + int xoff, yoff; + int framew, xpad, ypad; + XFontStruct *font; + int BW, BH; + + if (!b || !(b->flags & b_Icon)) + return; + + if (!b->IconWin) { + fprintf(stderr, + "%s: DEBUG: Tried to configure erroneous iconwindow\n", + MyName); + exit(2); + } + + buttonInfo(b, &x, &y, &xpad, &ypad, &framew); + framew = abs(framew); + + font = buttonFont(b); + w = b->icon->width; + h = b->icon->height; + BW = buttonWidth(b); + BH = buttonHeight(b); + + w = min(w, BW - 2 * (xpad + framew)); + + if (b->flags & b_Title && font && !(buttonJustify(b) & b_Horizontal)) + h = min( + h, BH - 2 * (ypad + framew) - font->ascent - font->descent); + else + h = min(h, BH - 2 * (ypad + framew)); + + if (w < 1 || h < 1) { + if (buttonSwallowCount(b) == 3) + XMoveWindow(Dpy, b->IconWin, 2000, 2000); + else + XMoveResizeWindow(Dpy, b->IconWin, 2000, 2000, 1, 1); + return; /* No need drawing to this */ + } + + if (buttonJustify(b) & b_Horizontal) + xoff = 0; + else + xoff = (BW - w) >> 1; + + if (b->flags & b_Title && font && !(buttonJustify(b) & b_Horizontal)) + yoff = (BH - (h + font->ascent + font->descent)) >> 1; + else + yoff = (BH - h) >> 1; + + if (xoff < framew + xpad) + xoff = framew + xpad; + if (yoff < framew + ypad) + yoff = framew + ypad; + + x += xoff; + y += yoff; + + XMoveResizeWindow(Dpy, b->IconWin, x, y, w, h); + + /* Doesn't this belong above? + #ifdef XPM + #ifdef SHAPE + if (b->icon->mask!=None) + { + XShapeCombineMask(Dpy,b->IconWin,ShapeBounding,0,0, + b->icon->mask,ShapeSet); + } + #endif + #endif + if(b->icon->depth==0) + { + PixmapFromBitmap(b); + } + XSetWindowBackgroundPixmap(Dpy,b->IconWin,b->icon->picture); + */ -#endif +#endif } Index: fvwm/modules/FvwmButtons/icons.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/icons.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/icons.h --- fvwm/modules/FvwmButtons/icons.h +++ fvwm/modules/FvwmButtons/icons.h @@ -13,8 +13,5 @@ */ /* ------------------------------ prototypes ------------------------------- */ -#if 0 -void LoadIconFile(button_info*); -#endif -void CreateIconWindow(button_info*); -void ConfigureIconWindow(button_info*); +void CreateIconWindow(button_info *); +void ConfigureIconWindow(button_info *); Index: fvwm/modules/FvwmButtons/misc.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/misc.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/misc.c --- fvwm/modules/FvwmButtons/misc.c +++ fvwm/modules/FvwmButtons/misc.c @@ -21,138 +21,126 @@ *** The general algorithm, especially the aspect ratio stuff, is borrowed from *** uwm's CheckConsistency routine. **/ -void ConstrainSize (XSizeHints *hints, int *widthp, int *heightp) +void +ConstrainSize(XSizeHints *hints, int *widthp, int *heightp) { -#define makemult(a,b) ((b==1) ? (a) : (((int)((a)/(b))) * (b)) ) +#define makemult(a, b) ((b == 1) ? (a) : (((int)((a) / (b))) * (b))) - int minWidth, minHeight, maxWidth, maxHeight, xinc, yinc, delta; - int baseWidth, baseHeight; - int dwidth = *widthp, dheight = *heightp; + int minWidth, minHeight, maxWidth, maxHeight, xinc, yinc, delta; + int baseWidth, baseHeight; + int dwidth = *widthp, dheight = *heightp; - if(hints->flags & PMinSize) - { - minWidth = hints->min_width; - minHeight = hints->min_height; - if(hints->flags & PBaseSize) - { - baseWidth = hints->base_width; - baseHeight = hints->base_height; + if (hints->flags & PMinSize) { + minWidth = hints->min_width; + minHeight = hints->min_height; + if (hints->flags & PBaseSize) { + baseWidth = hints->base_width; + baseHeight = hints->base_height; + } else { + baseWidth = hints->min_width; + baseHeight = hints->min_height; + } + } else if (hints->flags & PBaseSize) { + minWidth = hints->base_width; + minHeight = hints->base_height; + baseWidth = hints->base_width; + baseHeight = hints->base_height; + } else { + minWidth = 1; + minHeight = 1; + baseWidth = 1; + baseHeight = 1; } - else - { - baseWidth = hints->min_width; - baseHeight = hints->min_height; + + if (hints->flags & PMaxSize) { + maxWidth = hints->max_width; + maxHeight = hints->max_height; + } else { + maxWidth = 10000; + maxHeight = 10000; + } + if (hints->flags & PResizeInc) { + xinc = hints->width_inc; + yinc = hints->height_inc; + } else { + xinc = 1; + yinc = 1; } - } - else if(hints->flags & PBaseSize) - { - minWidth = hints->base_width; - minHeight = hints->base_height; - baseWidth = hints->base_width; - baseHeight = hints->base_height; - } - else - { - minWidth = 1; - minHeight = 1; - baseWidth = 1; - baseHeight = 1; - } - - if(hints->flags & PMaxSize) - { - maxWidth = hints->max_width; - maxHeight = hints->max_height; - } - else - { - maxWidth = 10000; - maxHeight = 10000; - } - if(hints->flags & PResizeInc) - { - xinc = hints->width_inc; - yinc = hints->height_inc; - } - else - { - xinc = 1; - yinc = 1; - } - - /* - * 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, fit to base + N * inc - */ - dwidth = ((dwidth - baseWidth) / xinc * xinc) + baseWidth; - dheight = ((dheight - baseHeight) / yinc * yinc) + baseHeight; - - - /* - * Third, adjust for aspect ratio - */ + + /* + * 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, fit to base + N * inc + */ + dwidth = ((dwidth - baseWidth) / xinc * xinc) + baseWidth; + dheight = ((dheight - baseHeight) / yinc * yinc) + baseHeight; + + /* + * Third, adjust for aspect ratio + */ #define maxAspectX hints->max_aspect.x #define maxAspectY hints->max_aspect.y #define minAspectX hints->min_aspect.x #define minAspectY 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 (hints->flags & PAspect) - { - if (minAspectX * dheight > minAspectY * dwidth) - { - delta = makemult(minAspectX * dheight / minAspectY - dwidth, - xinc); - if (dwidth + delta <= maxWidth) - dwidth += delta; - else - { - delta = makemult(dheight - dwidth*minAspectY/minAspectX, - yinc); - if (dheight - delta >= minHeight) dheight -= delta; - } - } - - if (maxAspectX * dheight < maxAspectY * dwidth) - { - delta = makemult(dwidth * maxAspectY / maxAspectX - dheight, - yinc); - if (dheight + delta <= maxHeight) - dheight += delta; - else - { - delta = makemult(dwidth - maxAspectX*dheight/maxAspectY, - xinc); - if (dwidth - delta >= minWidth) dwidth -= delta; - } + /* + * 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 (hints->flags & PAspect) { + if (minAspectX * dheight > minAspectY * dwidth) { + delta = makemult( + minAspectX * dheight / minAspectY - dwidth, xinc); + if (dwidth + delta <= maxWidth) + dwidth += delta; + else { + delta = makemult( + dheight - dwidth * minAspectY / minAspectX, + yinc); + if (dheight - delta >= minHeight) + dheight -= delta; + } + } + + if (maxAspectX * dheight < maxAspectY * dwidth) { + delta = makemult( + dwidth * maxAspectY / maxAspectX - dheight, yinc); + if (dheight + delta <= maxHeight) + dheight += delta; + else { + delta = makemult( + dwidth - maxAspectX * dheight / maxAspectY, + xinc); + if (dwidth - delta >= minWidth) + dwidth -= delta; + } + } } - } - - *widthp = dwidth; - *heightp = dheight; - return; + + *widthp = dwidth; + *heightp = dheight; + return; #undef makemult #undef maxAspectX #undef maxAspectY Index: fvwm/modules/FvwmButtons/misc.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/misc.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/misc.h --- fvwm/modules/FvwmButtons/misc.h +++ fvwm/modules/FvwmButtons/misc.h @@ -15,4 +15,4 @@ #include #include -void ConstrainSize (XSizeHints *hints, int *widthp, int *heightp); +void ConstrainSize(XSizeHints *hints, int *widthp, int *heightp); Index: fvwm/modules/FvwmButtons/output.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/output.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/output.c --- fvwm/modules/FvwmButtons/output.c +++ fvwm/modules/FvwmButtons/output.c @@ -12,268 +12,259 @@ */ -#include +#include #include -#include #include -#include +#include +#include + #include "FvwmButtons.h" /** *** DumpButtons() *** Debug function. May only be called after ShuffleButtons has been called. **/ -void DumpButtons(button_info *b) +void +DumpButtons(button_info *b) { - if(!b) - { - fprintf(stderr,"NULL\n"); - return; - } - if(b!=UberButton) - { - int button=buttonNum(b); - fprintf(stderr,"0x%lx(%ix%i@(%i,%i),0x%04lx): ", - (unsigned long)b,b->BWidth,b->BHeight, - buttonXPos(b,button),buttonYPos(b,button),b->flags); - } - else - fprintf(stderr,"0x%lx(%ix%i@,0x%04lx): ",(unsigned long)b, - b->BWidth,b->BHeight,b->flags); - - if(b->flags&b_Font) - fprintf(stderr,"Font(%s,0x%lx) ",b->font_string,(unsigned long)b->font); - if(b->flags&b_Padding) - fprintf(stderr,"Padding(%i,%i) ",b->xpad,b->ypad); - if(b->flags&b_Frame) - fprintf(stderr,"Framew(%i) ",b->framew); - if(b->flags&b_Title) - fprintf(stderr,"Title(%s) ",b->title); - if(b->flags&b_Icon) - fprintf(stderr,"Icon(%s,%i) ",b->icon_file,(int)b->IconWin); - if(b->flags&b_Action) - fprintf(stderr,"\n Action(%s,%s,%s,%s) ", - b->action[0]?b->action[0]:"", - b->action[1]?b->action[1]:"", - b->action[2]?b->action[2]:"", - b->action[3]?b->action[3]:""); - if(b->flags&b_Swallow) - { - fprintf(stderr,"Swallow(0x%02x) ",b->swallow); - if(b->swallow&b_Respawn) - fprintf(stderr,"\n Respawn(%s) ",b->spawn); - } - if(b->flags&b_Hangon) - fprintf(stderr,"Hangon(%s) ",b->hangon); - fprintf(stderr,"\n"); - if(b->flags&b_Container) - { - int i=0; - fprintf(stderr," Container(%ix%i=%i buttons 0x%04lx (alloc %i), size %ix%i, pos %i,%i)\n{ ", - b->c->num_columns,b->c->num_rows,b->c->num_buttons,b->c->flags, - b->c->allocated_buttons, - b->c->ButtonWidth,b->c->ButtonHeight,b->c->xpos,b->c->ypos); -/* - fprintf(stderr," font(%s,%i) framew(%i) pad(%i,%i) { ", - b->c->font_string,(int)b->c->font,b->c->framew,b->c->xpad, - b->c->ypad); -*/ - while(ic->num_buttons) - fprintf(stderr,"0x%lx ",(unsigned long)b->c->buttons[i++]); - fprintf(stderr,"}\n"); - i=0; - while(ic->num_buttons) - DumpButtons(b->c->buttons[i++]); - return; - } + if (!b) { + fprintf(stderr, "NULL\n"); + return; + } + if (b != UberButton) { + int button = buttonNum(b); + fprintf(stderr, + "0x%lx(%ix%i@(%i,%i),0x%04lx): ", (unsigned long)b, + b->BWidth, b->BHeight, buttonXPos(b, button), + buttonYPos(b, button), b->flags); + } else + fprintf(stderr, "0x%lx(%ix%i@,0x%04lx): ", (unsigned long)b, + b->BWidth, b->BHeight, b->flags); + + if (b->flags & b_Font) + fprintf(stderr, "Font(%s,0x%lx) ", b->font_string, + (unsigned long)b->font); + if (b->flags & b_Padding) + fprintf(stderr, "Padding(%i,%i) ", b->xpad, b->ypad); + if (b->flags & b_Frame) + fprintf(stderr, "Framew(%i) ", b->framew); + if (b->flags & b_Title) + fprintf(stderr, "Title(%s) ", b->title); + if (b->flags & b_Icon) + fprintf(stderr, "Icon(%s,%i) ", b->icon_file, (int)b->IconWin); + if (b->flags & b_Action) + fprintf(stderr, "\n Action(%s,%s,%s,%s) ", + b->action[0] ? b->action[0] : "", + b->action[1] ? b->action[1] : "", + b->action[2] ? b->action[2] : "", + b->action[3] ? b->action[3] : ""); + if (b->flags & b_Swallow) { + fprintf(stderr, "Swallow(0x%02x) ", b->swallow); + if (b->swallow & b_Respawn) + fprintf(stderr, "\n Respawn(%s) ", b->spawn); + } + if (b->flags & b_Hangon) + fprintf(stderr, "Hangon(%s) ", b->hangon); + fprintf(stderr, "\n"); + if (b->flags & b_Container) { + int i = 0; + fprintf(stderr, + " Container(%ix%i=%i buttons 0x%04lx (alloc %i), size " + "%ix%i, pos %i,%i)\n{ ", + b->c->num_columns, b->c->num_rows, b->c->num_buttons, + b->c->flags, b->c->allocated_buttons, b->c->ButtonWidth, + b->c->ButtonHeight, b->c->xpos, b->c->ypos); + /* + fprintf(stderr," font(%s,%i) framew(%i) pad(%i,%i) { ", + b->c->font_string,(int)b->c->font,b->c->framew,b->c->xpad, + b->c->ypad); + */ + while (i < b->c->num_buttons) + fprintf(stderr, "0x%lx ", + (unsigned long)b->c->buttons[i++]); + fprintf(stderr, "}\n"); + i = 0; + while (i < b->c->num_buttons) + DumpButtons(b->c->buttons[i++]); + return; + } } -void SaveButtons(button_info *b) +void +SaveButtons(button_info *b) { - int i; - if(!b) - return; - if(b->BWidth>1 || b->BHeight>1) - fprintf(stderr,"%ix%i ",b->BWidth,b->BHeight); - if(b->flags&b_Font) - fprintf(stderr,"Font %s ",b->font_string); - if(b->flags&b_Fore) - fprintf(stderr,"Fore %s ",b->fore); - if(b->flags&b_Back) - fprintf(stderr,"Back %s ",b->back); - if(b->flags&b_Frame) - fprintf(stderr,"Frame %i ",b->framew); - if(b->flags&b_Padding) - fprintf(stderr,"Padding %i %i ",b->xpad,b->ypad); - if(b->flags&b_Title) - { - fprintf(stderr,"Title "); - if(b->flags&b_Justify) - { - fprintf(stderr,"("); - switch(b->justify&b_TitleHoriz) - { - case 0: - fprintf(stderr,"Left"); - break; - case 1: - fprintf(stderr,"Center"); - break; - case 2: - fprintf(stderr,"Right"); - break; - } - if(b->justify&b_Horizontal) - fprintf(stderr,", Side"); - fprintf(stderr,") "); + int i; + if (!b) + return; + if (b->BWidth > 1 || b->BHeight > 1) + fprintf(stderr, "%ix%i ", b->BWidth, b->BHeight); + if (b->flags & b_Font) + fprintf(stderr, "Font %s ", b->font_string); + if (b->flags & b_Fore) + fprintf(stderr, "Fore %s ", b->fore); + if (b->flags & b_Back) + fprintf(stderr, "Back %s ", b->back); + if (b->flags & b_Frame) + fprintf(stderr, "Frame %i ", b->framew); + if (b->flags & b_Padding) + fprintf(stderr, "Padding %i %i ", b->xpad, b->ypad); + if (b->flags & b_Title) { + fprintf(stderr, "Title "); + if (b->flags & b_Justify) { + fprintf(stderr, "("); + switch (b->justify & b_TitleHoriz) { + case 0: + fprintf(stderr, "Left"); + break; + case 1: + fprintf(stderr, "Center"); + break; + case 2: + fprintf(stderr, "Right"); + break; + } + if (b->justify & b_Horizontal) + fprintf(stderr, ", Side"); + fprintf(stderr, ") "); + } + fprintf(stderr, "\"%s\" ", b->title); + } + if (b->flags & b_Icon) + fprintf(stderr, "Icon \"%s\" ", b->icon_file); + if (b->flags & b_Swallow) { + fprintf(stderr, "Swallow "); + if (b->swallow_mask) { + fprintf(stderr, "("); + if (b->swallow_mask & b_NoHints) { + if (b->swallow & b_NoHints) + fprintf(stderr, "NoHints "); + else + fprintf(stderr, "Hints "); + } + if (b->swallow_mask & b_Kill) { + if (b->swallow & b_Kill) + fprintf(stderr, "Kill "); + else + fprintf(stderr, "NoKill "); + } + if (b->swallow_mask & b_NoClose) { + if (b->swallow & b_NoClose) + fprintf(stderr, "NoClose "); + else + fprintf(stderr, "Close "); + } + if (b->swallow_mask & b_Respawn) { + if (b->swallow & b_Respawn) + fprintf(stderr, "Respawn "); + else + fprintf(stderr, "NoRespawn "); + } + if (b->swallow_mask & b_UseOld) { + if (b->swallow & b_UseOld) + fprintf(stderr, "UseOld "); + else + fprintf(stderr, "NoOld "); + } + if (b->swallow_mask & b_UseTitle) { + if (b->swallow & b_UseTitle) + fprintf(stderr, "UseTitle "); + else + fprintf(stderr, "NoTitle "); + } + fprintf(stderr, ") "); + } + fprintf(stderr, "\"%s\" \"%s\" ", b->hangon, b->spawn); } - fprintf(stderr,"\"%s\" ",b->title); - } - if(b->flags&b_Icon) - fprintf(stderr,"Icon \"%s\" ",b->icon_file); - if(b->flags&b_Swallow) - { - fprintf(stderr,"Swallow "); - if(b->swallow_mask) - { - fprintf(stderr,"("); - if(b->swallow_mask&b_NoHints) { - if(b->swallow&b_NoHints) - fprintf(stderr,"NoHints "); - else - fprintf(stderr,"Hints "); - } - if(b->swallow_mask&b_Kill) { - if(b->swallow&b_Kill) - fprintf(stderr,"Kill "); - else - fprintf(stderr,"NoKill "); - } - if(b->swallow_mask&b_NoClose) { - if(b->swallow&b_NoClose) - fprintf(stderr,"NoClose "); - else - fprintf(stderr,"Close "); - } - if(b->swallow_mask&b_Respawn) { - if(b->swallow&b_Respawn) - fprintf(stderr,"Respawn "); - else - fprintf(stderr,"NoRespawn "); - } - if(b->swallow_mask&b_UseOld) { - if(b->swallow&b_UseOld) - fprintf(stderr,"UseOld "); - else - fprintf(stderr,"NoOld "); - } - if(b->swallow_mask&b_UseTitle) { - if(b->swallow&b_UseTitle) - fprintf(stderr,"UseTitle "); - else - fprintf(stderr,"NoTitle "); - } - fprintf(stderr,") "); + if (b->flags & b_Action) { + if (b->action[0]) + fprintf(stderr, "Action `%s` ", b->action[0]); + for (i = 1; i < 4; i++) + if (b->action[i]) + fprintf(stderr, "Action (Mouse %i) `%s` ", i, + b->action[i]); } - fprintf(stderr,"\"%s\" \"%s\" ",b->hangon,b->spawn); - } - if(b->flags&b_Action) - { - if(b->action[0]) - fprintf(stderr,"Action `%s` ",b->action[0]); - for(i=1;i<4;i++) - if(b->action[i]) - fprintf(stderr,"Action (Mouse %i) `%s` ",i,b->action[i]); - } - - if(b->flags&b_Container) - { - fprintf(stderr,"Container (Columns %i Rows %i ",b->c->num_columns, - b->c->num_rows); - if(b->c->flags) - { - if(b->c->flags&b_Font) - fprintf(stderr,"Font %s ",b->c->font_string); - if(b->c->flags&b_Fore) - fprintf(stderr,"Fore %s ",b->c->fore); - if(b->c->flags&b_Back) - fprintf(stderr,"Back %s ",b->c->back); - if(b->c->flags&b_Frame) - fprintf(stderr,"Frame %i ",b->c->framew); - if(b->c->flags&b_Padding) - fprintf(stderr,"Padding %i %i ",b->c->xpad,b->c->ypad); - if(b->c->flags&b_Justify) - { - fprintf(stderr,"Title ("); - switch(b->c->justify&b_TitleHoriz) - { - case 0: - fprintf(stderr,"Left"); - break; - case 1: - fprintf(stderr,"Center"); - break; - case 2: - fprintf(stderr,"Right"); - break; + if (b->flags & b_Container) { + fprintf(stderr, "Container (Columns %i Rows %i ", + b->c->num_columns, b->c->num_rows); + if (b->c->flags) { + if (b->c->flags & b_Font) + fprintf(stderr, "Font %s ", b->c->font_string); + if (b->c->flags & b_Fore) + fprintf(stderr, "Fore %s ", b->c->fore); + if (b->c->flags & b_Back) + fprintf(stderr, "Back %s ", b->c->back); + if (b->c->flags & b_Frame) + fprintf(stderr, "Frame %i ", b->c->framew); + if (b->c->flags & b_Padding) + fprintf(stderr, "Padding %i %i ", b->c->xpad, + b->c->ypad); + if (b->c->flags & b_Justify) { + fprintf(stderr, "Title ("); + switch (b->c->justify & b_TitleHoriz) { + case 0: + fprintf(stderr, "Left"); + break; + case 1: + fprintf(stderr, "Center"); + break; + case 2: + fprintf(stderr, "Right"); + break; + } + if (b->c->justify & b_Horizontal) + fprintf(stderr, ", Side"); + fprintf(stderr, ") "); + } + if (b->c->swallow_mask) { + fprintf(stderr, "Swallow ("); + if (b->c->swallow_mask & b_NoHints) { + if (b->c->swallow & b_NoHints) + fprintf(stderr, "NoHints "); + else + fprintf(stderr, "Hints "); + } + if (b->c->swallow_mask & b_Kill) { + if (b->c->swallow & b_Kill) + fprintf(stderr, "Kill "); + else + fprintf(stderr, "NoKill "); + } + if (b->c->swallow_mask & b_NoClose) { + if (b->c->swallow & b_NoClose) + fprintf(stderr, "NoClose "); + else + fprintf(stderr, "Close "); + } + if (b->c->swallow_mask & b_Respawn) { + if (b->c->swallow & b_Respawn) + fprintf(stderr, "Respawn "); + else + fprintf(stderr, "NoRespawn "); + } + if (b->c->swallow_mask & b_UseOld) { + if (b->c->swallow & b_UseOld) + fprintf(stderr, "UseOld "); + else + fprintf(stderr, "NoOld "); + } + if (b->c->swallow_mask & b_UseTitle) { + if (b->c->swallow & b_UseTitle) + fprintf(stderr, "UseTitle "); + else + fprintf(stderr, "NoTitle "); + } + fprintf(stderr, ") "); + } } - if(b->c->justify&b_Horizontal) - fprintf(stderr,", Side"); - fprintf(stderr,") "); - } - if(b->c->swallow_mask) - { - fprintf(stderr,"Swallow ("); - if(b->c->swallow_mask&b_NoHints) { - if(b->c->swallow&b_NoHints) - fprintf(stderr,"NoHints "); - else - fprintf(stderr,"Hints "); - } - if(b->c->swallow_mask&b_Kill) { - if(b->c->swallow&b_Kill) - fprintf(stderr,"Kill "); - else - fprintf(stderr,"NoKill "); - } - if(b->c->swallow_mask&b_NoClose) { - if(b->c->swallow&b_NoClose) - fprintf(stderr,"NoClose "); - else - fprintf(stderr,"Close "); - } - if(b->c->swallow_mask&b_Respawn) { - if(b->c->swallow&b_Respawn) - fprintf(stderr,"Respawn "); - else - fprintf(stderr,"NoRespawn "); - } - if(b->c->swallow_mask&b_UseOld) { - if(b->c->swallow&b_UseOld) - fprintf(stderr,"UseOld "); - else - fprintf(stderr,"NoOld "); - } - if(b->c->swallow_mask&b_UseTitle) { - if(b->c->swallow&b_UseTitle) - fprintf(stderr,"UseTitle "); - else - fprintf(stderr,"NoTitle "); - } - fprintf(stderr,") "); - } + fprintf(stderr, ")"); } - fprintf(stderr,")"); - } - fprintf(stderr,"\n"); - - if(b->flags&b_Container) - { - i=0; - while(ic->num_buttons) - SaveButtons(b->c->buttons[i++]); - fprintf(stderr,"End\n"); - } -} + fprintf(stderr, "\n"); + if (b->flags & b_Container) { + i = 0; + while (i < b->c->num_buttons) + SaveButtons(b->c->buttons[i++]); + fprintf(stderr, "End\n"); + } +} Index: fvwm/modules/FvwmButtons/parse.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/parse.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/parse.c --- fvwm/modules/FvwmButtons/parse.c +++ fvwm/modules/FvwmButtons/parse.c @@ -12,15 +12,14 @@ */ -#include "config.h" - +#include +#include #include #include #include #include -#include -#include +#include "config.h" /* #include #include @@ -30,7 +29,7 @@ #include "FvwmButtons.h" #include "button.h" -extern int w,h,x,y,xneg,yneg; /* used in ParseConfigLine */ +extern int w, h, x, y, xneg, yneg; /* used in ParseConfigLine */ extern char *config_file; /* contains the character that terminated the last string from seekright */ @@ -38,11 +37,12 @@ static char terminator = '\0'; /* ----------------------------------- macros ------------------------------ */ -char *trimleft(char *s) +char * +trimleft(char *s) { - while (s && isspace(*s)) - s++; - return s; + while (s && isspace(*s)) + s++; + return s; } /** @@ -52,358 +52,403 @@ char *trimleft(char *s) *** string and move the old pointer forward. Accepts and strips quoting with *** '," or `, and the current quote q can be escaped inside the string with \q. **/ -char *seekright(char **s) +char * +seekright(char **s) { - char *token = NULL; - char *line = *s; + char *token = NULL; + char *line = *s; - line = DoGetNextToken(line, &token, NULL, "),", &terminator); - if (*s != NULL && line == NULL) - line = strchr(*s, '\0'); - *s = line; + line = DoGetNextToken(line, &token, NULL, "),", &terminator); + if (*s != NULL && line == NULL) + line = strchr(*s, '\0'); + *s = line; + + return token; +} + +static char * +seekright_command(char **s) +{ + char *command = seekright(s); + + if (command == NULL) + return NULL; + + while (terminator != '\0' && terminator != ')' && terminator != ',') { + char *next = seekright(s); + + if (next == NULL) + break; + + size_t len_command = strlen(command); + size_t len_next = strlen(next); + char *combined = xmalloc(len_command + len_next + 2); + + memcpy(combined, command, len_command); + combined[len_command] = ' '; + memcpy(combined + len_command + 1, next, len_next + 1); + + free(command); + free(next); + command = combined; + } - return token; + return command; } /** *** ParseBack() *** Parses the options possible to Back **/ -int ParseBack(char **ss) +int +ParseBack(char **ss) { - char *opts[]={"icon",NULL}; - char *t,*s=*ss; - int r=0; - - while(*s && *s!=')') - { - s = trimleft(s); - if(*s==',') - s++; - else switch(GetTokenIndex(s,opts,-1,&s)) - { - case 0: /* Icon */ - r=1; - fprintf(stderr,"%s: Back(Icon) not supported yet\n",MyName); - break; - default: - t=seekright(&s); - fprintf(stderr,"%s: Illegal back option \"%s\"\n",MyName,(t)?t:""); - if (t) - free(t); + char *opts[] = {"icon", NULL}; + char *t, *s = *ss; + int r = 0; + + while (*s && *s != ')') { + s = trimleft(s); + if (*s == ',') + s++; + else + switch (GetTokenIndex(s, opts, -1, &s)) { + case 0: /* Icon */ + r = 1; + fprintf(stderr, + "%s: Back(Icon) not supported yet\n", + MyName); + break; + default: + t = seekright(&s); + fprintf(stderr, + "%s: Illegal back option \"%s\"\n", MyName, + (t) ? t : ""); + if (t) + free(t); + } } - } - if(*s) s++; - *ss=s; - return r; + if (*s) + s++; + *ss = s; + return r; } /** *** ParseBoxSize() *** Parses the options possible to BoxSize **/ -void ParseBoxSize(char **ss, unsigned long *flags) +void +ParseBoxSize(char **ss, unsigned long *flags) { - char *opts[]={"dumb","fixed","smart",NULL}; - char *s = *ss; - int m; - - if (!s) - return; - *ss = GetNextTokenIndex(*ss, opts, 0, &m); - switch(m) - { - case 0: - *flags &= ~(b_SizeFixed|b_SizeSmart); - break; - case 1: - *flags |= b_SizeFixed; - *flags &= ~b_SizeSmart; - break; - case 2: - *flags |= b_SizeSmart; - *flags &= ~b_SizeFixed; - break; - default: - *flags &= ~(b_SizeFixed|b_SizeSmart); - fprintf(stderr,"%s: Illegal boxsize option \"%s\"\n",MyName, s); - break; - } - return; + char *opts[] = {"dumb", "fixed", "smart", NULL}; + char *s = *ss; + int m; + + if (!s) + return; + *ss = GetNextTokenIndex(*ss, opts, 0, &m); + switch (m) { + case 0: + *flags &= ~(b_SizeFixed | b_SizeSmart); + break; + case 1: + *flags |= b_SizeFixed; + *flags &= ~b_SizeSmart; + break; + case 2: + *flags |= b_SizeSmart; + *flags &= ~b_SizeFixed; + break; + default: + *flags &= ~(b_SizeFixed | b_SizeSmart); + fprintf( + stderr, "%s: Illegal boxsize option \"%s\"\n", MyName, s); + break; + } + return; } /** *** ParseTitle() *** Parses the options possible to Title **/ -void ParseTitle(char **ss, byte *flags, byte *mask) +void +ParseTitle(char **ss, byte *flags, byte *mask) { - char *titleopts[]={"left","right","center","side",NULL}; - char *t,*s=*ss; - - while(*s && *s!=')') - { - s = trimleft(s); - if(*s==',') - s++; - else switch(GetTokenIndex(s,titleopts,-1,&s)) - { - case 0: /* Left */ - *flags&=~b_TitleHoriz; - *mask|=b_TitleHoriz; - break; - case 1: /* Right */ - *flags&=~b_TitleHoriz; - *flags|=2; - *mask|=b_TitleHoriz; - break; - case 2: /* Center */ - *flags&=~b_TitleHoriz; - *flags|=1; - *mask|=b_TitleHoriz; - break; - case 3: /* Side */ - *flags|=b_Horizontal; - *mask|=b_Horizontal; - break; - default: - t=seekright(&s); - fprintf(stderr,"%s: Illegal title option \"%s\"\n",MyName,(t)?t:""); - if (t) - free(t); + char *titleopts[] = {"left", "right", "center", "side", NULL}; + char *t, *s = *ss; + + while (*s && *s != ')') { + s = trimleft(s); + if (*s == ',') + s++; + else + switch (GetTokenIndex(s, titleopts, -1, &s)) { + case 0: /* Left */ + *flags &= ~b_TitleHoriz; + *mask |= b_TitleHoriz; + break; + case 1: /* Right */ + *flags &= ~b_TitleHoriz; + *flags |= 2; + *mask |= b_TitleHoriz; + break; + case 2: /* Center */ + *flags &= ~b_TitleHoriz; + *flags |= 1; + *mask |= b_TitleHoriz; + break; + case 3: /* Side */ + *flags |= b_Horizontal; + *mask |= b_Horizontal; + break; + default: + t = seekright(&s); + fprintf(stderr, + "%s: Illegal title option \"%s\"\n", MyName, + (t) ? t : ""); + if (t) + free(t); + } } - } - if(*s) s++; - *ss=s; + if (*s) + s++; + *ss = s; } /** *** ParseSwallow() *** Parses the options possible to Swallow **/ -void ParseSwallow(char **ss,byte *flags,byte *mask) +void +ParseSwallow(char **ss, byte *flags, byte *mask) { - char *swallowopts[]={"nohints","hints","nokill","kill","noclose","close", - "respawn","norespawn","useold", - "noold","usetitle","notitle",NULL}; - char *t,*s=*ss; - - while(*s && *s!=')') - { - s = trimleft(s); - if(*s==',') - s++; - else switch(GetTokenIndex(s,swallowopts,-1,&s)) - { - case 0: /* NoHints */ - *flags|=b_NoHints; - *mask|=b_NoHints; - break; - case 1: /* Hints */ - *flags&=~b_NoHints; - *mask|=b_NoHints; - break; - case 2: /* NoKill */ - *flags&=~b_Kill; - *mask|=b_Kill; - break; - case 3: /* Kill */ - *flags|=b_Kill; - *mask|=b_Kill; - break; - case 4: /* NoClose */ - *flags|=b_NoClose; - *mask|=b_NoClose; - break; - case 5: /* Close */ - *flags&=~b_NoClose; - *mask|=b_NoClose; - break; - case 6: /* Respawn */ - *flags|=b_Respawn; - *mask|=b_Respawn; - break; - case 7: /* NoRespawn */ - *flags&=~b_Respawn; - *mask|=b_Respawn; - break; - case 8: /* UseOld */ - *flags|=b_UseOld; - *mask|=b_UseOld; - break; - case 9: /* NoOld */ - *flags&=~b_UseOld; - *mask|=b_UseOld; - break; - case 10: /* UseTitle */ - *flags|=b_UseTitle; - *mask|=b_UseTitle; - break; - case 11: /* NoTitle */ - *flags&=~b_UseTitle; - *mask|=b_UseTitle; - break; - default: - t=seekright(&s); - fprintf(stderr,"%s: Illegal swallow option \"%s\"\n",MyName, - (t)?t:""); - if (t) - free(t); + char *swallowopts[] = {"nohints", "hints", "nokill", "kill", "noclose", + "close", "respawn", "norespawn", "useold", "noold", "usetitle", + "notitle", NULL}; + char *t, *s = *ss; + + while (*s && *s != ')') { + s = trimleft(s); + if (*s == ',') + s++; + else + switch (GetTokenIndex(s, swallowopts, -1, &s)) { + case 0: /* NoHints */ + *flags |= b_NoHints; + *mask |= b_NoHints; + break; + case 1: /* Hints */ + *flags &= ~b_NoHints; + *mask |= b_NoHints; + break; + case 2: /* NoKill */ + *flags &= ~b_Kill; + *mask |= b_Kill; + break; + case 3: /* Kill */ + *flags |= b_Kill; + *mask |= b_Kill; + break; + case 4: /* NoClose */ + *flags |= b_NoClose; + *mask |= b_NoClose; + break; + case 5: /* Close */ + *flags &= ~b_NoClose; + *mask |= b_NoClose; + break; + case 6: /* Respawn */ + *flags |= b_Respawn; + *mask |= b_Respawn; + break; + case 7: /* NoRespawn */ + *flags &= ~b_Respawn; + *mask |= b_Respawn; + break; + case 8: /* UseOld */ + *flags |= b_UseOld; + *mask |= b_UseOld; + break; + case 9: /* NoOld */ + *flags &= ~b_UseOld; + *mask |= b_UseOld; + break; + case 10: /* UseTitle */ + *flags |= b_UseTitle; + *mask |= b_UseTitle; + break; + case 11: /* NoTitle */ + *flags &= ~b_UseTitle; + *mask |= b_UseTitle; + break; + default: + t = seekright(&s); + fprintf(stderr, + "%s: Illegal swallow option \"%s\"\n", + MyName, (t) ? t : ""); + if (t) + free(t); + } } - } - if(*s) s++; - *ss=s; + if (*s) + s++; + *ss = s; } /** *** ParseContainer() *** Parses the options possible to Container **/ -void ParseContainer(char **ss,button_info *b) +void +ParseContainer(char **ss, button_info *b) { - char *conts[]={"columns","rows","font","frame","back","fore", - "padding","title","swallow","nosize","size", - "boxsize",NULL}; - char *t,*o,*s=*ss; - int i,j; - - while(*s && *s!=')') - { - s = trimleft(s); - if(*s==',') - s++; - else switch(GetTokenIndex(s,conts,-1,&s)) - { - case 0: /* Columns */ - b->c->num_columns=max(1,strtol(s,&t,10)); - s=t; - break; - case 1: /* Rows */ - b->c->num_rows=max(1,strtol(s,&t,10)); - s=t; - break; - case 2: /* Font */ - if (b->c->font_string) free(b->c->font_string); - b->c->font_string=seekright(&s); - if(b->c->font_string) - b->c->flags|=b_Font; - else - b->c->flags&=~b_Font; - break; - case 3: /* Frame */ - b->c->framew=strtol(s,&t,10); - b->c->flags|=b_Frame; - s=t; - break; - case 4: /* Back */ - s = trimleft(s); - if(*s=='(' && s++) - if(ParseBack(&s)) - b->c->flags|=b_IconBack; - if (b->c->back) free(b->c->back); - b->c->back=seekright(&s); - if(b->c->back) - b->c->flags|=b_Back; - else - b->c->flags&=~(b_IconBack|b_Back); - break; - case 5: /* Fore */ - if (b->c->fore) free(b->c->fore); - b->c->fore=seekright(&s); - if(b->c->fore) - b->c->flags|=b_Fore; - else - b->c->flags&=~b_Fore; - break; - case 6: /* Padding */ - i=strtol(s,&t,10); - if(t>s) - { - b->c->xpad=b->c->ypad=i; - s=t; - i=strtol(s,&t,10); - if(t>s) - { - b->c->ypad=i; - s=t; - } - b->c->flags|=b_Padding; - } - else - fprintf(stderr,"%s: Illegal padding argument\n",MyName); - break; - case 7: /* Title - flags */ - s = trimleft(s); - if(*s=='(' && s++) - { - b->c->justify=0; - b->c->justify_mask=0; - ParseTitle(&s,&b->c->justify,&b->c->justify_mask); - if(b->c->justify_mask) - b->c->flags|=b_Justify; - } - else - { - char *temp; - fprintf(stderr,"%s: Illegal title in container options\n", - MyName); - temp = seekright(&s); - if (temp) - free(temp); - } - break; - case 8: /* Swallow - flags */ - s = trimleft(s); - if(*s=='(' && s++) - { - b->c->swallow=0; - b->c->swallow_mask=0; - ParseSwallow(&s,&b->c->swallow,&b->c->swallow_mask); - if(b->c->swallow_mask) - b->c->flags|=b_Swallow; - } - else - { - char *temp; - fprintf(stderr,"%s: Illegal swallow in container options\n", - MyName); - temp = seekright(&s); - if (temp) - free(temp); - } - break; - case 9: /* NoSize */ - b->c->flags|=b_Size; - b->c->minx=b->c->miny=0; - break; - - case 10: /* Size */ - i=strtol(s,&t,10); - j=strtol(t,&o,10); - if(t>s && o>t) - { - b->c->minx=i; - b->c->miny=j; - b->c->flags|=b_Size; - s=o; - } - else - fprintf(stderr,"%s: Illegal size arguments\n",MyName); - break; - case 11: /* BoxSize */ - ParseBoxSize(&s, &b->c->flags); - break; - - default: - t=seekright(&s); - fprintf(stderr,"%s: Illegal container option \"%s\"\n",MyName, - (t)?t:""); - if (t) - free(t); + char *conts[] = {"columns", "rows", "font", "frame", "back", "fore", + "padding", "title", "swallow", "nosize", "size", "boxsize", NULL}; + char *t, *o, *s = *ss; + int i, j; + + while (*s && *s != ')') { + s = trimleft(s); + if (*s == ',') + s++; + else + switch (GetTokenIndex(s, conts, -1, &s)) { + case 0: /* Columns */ + b->c->num_columns = max(1, strtol(s, &t, 10)); + s = t; + break; + case 1: /* Rows */ + b->c->num_rows = max(1, strtol(s, &t, 10)); + s = t; + break; + case 2: /* Font */ + if (b->c->font_string) + free(b->c->font_string); + b->c->font_string = seekright(&s); + if (b->c->font_string) + b->c->flags |= b_Font; + else + b->c->flags &= ~b_Font; + break; + case 3: /* Frame */ + b->c->framew = strtol(s, &t, 10); + b->c->flags |= b_Frame; + s = t; + break; + case 4: /* Back */ + s = trimleft(s); + if (*s == '(' && s++) + if (ParseBack(&s)) + b->c->flags |= b_IconBack; + if (b->c->back) + free(b->c->back); + b->c->back = seekright(&s); + if (b->c->back) + b->c->flags |= b_Back; + else + b->c->flags &= ~(b_IconBack | b_Back); + break; + case 5: /* Fore */ + if (b->c->fore) + free(b->c->fore); + b->c->fore = seekright(&s); + if (b->c->fore) + b->c->flags |= b_Fore; + else + b->c->flags &= ~b_Fore; + break; + case 6: /* Padding */ + i = strtol(s, &t, 10); + if (t > s) { + b->c->xpad = b->c->ypad = i; + s = t; + i = strtol(s, &t, 10); + if (t > s) { + b->c->ypad = i; + s = t; + } + b->c->flags |= b_Padding; + } else + fprintf(stderr, + "%s: Illegal padding argument\n", + MyName); + break; + case 7: /* Title - flags */ + s = trimleft(s); + if (*s == '(' && s++) { + b->c->justify = 0; + b->c->justify_mask = 0; + ParseTitle(&s, &b->c->justify, + &b->c->justify_mask); + if (b->c->justify_mask) + b->c->flags |= b_Justify; + } else { + char *temp; + fprintf(stderr, + "%s: Illegal title in container " + "options\n", + MyName); + temp = seekright(&s); + if (temp) + free(temp); + } + break; + case 8: /* Swallow - flags */ + s = trimleft(s); + if (*s == '(' && s++) { + b->c->swallow = 0; + b->c->swallow_mask = 0; + ParseSwallow(&s, &b->c->swallow, + &b->c->swallow_mask); + if (b->c->swallow_mask) + b->c->flags |= b_Swallow; + } else { + char *temp; + fprintf(stderr, + "%s: Illegal swallow in container " + "options\n", + MyName); + temp = seekright(&s); + if (temp) + free(temp); + } + break; + case 9: /* NoSize */ + b->c->flags |= b_Size; + b->c->minx = b->c->miny = 0; + break; + + case 10: /* Size */ + i = strtol(s, &t, 10); + j = strtol(t, &o, 10); + if (t > s && o > t) { + b->c->minx = i; + b->c->miny = j; + b->c->flags |= b_Size; + s = o; + } else + fprintf(stderr, + "%s: Illegal size arguments\n", + MyName); + break; + case 11: /* BoxSize */ + ParseBoxSize(&s, &b->c->flags); + break; + + default: + t = seekright(&s); + fprintf(stderr, + "%s: Illegal container option \"%s\"\n", + MyName, (t) ? t : ""); + if (t) + free(t); + } } - } - if(*s) s++; - *ss=s; + if (*s) + s++; + *ss = s; } /** @@ -413,610 +458,635 @@ void ParseContainer(char **ss,button_info *b) *** *FvwmButtons(option[ options]) title iconname command **/ /*#define DEBUG_PARSER*/ -void match_string(button_info **uberb,char *s) +void +match_string(button_info **uberb, char *s) { - button_info *b,*ub=*uberb; - int i,j; - char *t,*o; - b=alloc_button(ub,(ub->c->num_buttons)++); - s = trimleft(s); - - if(*s=='(' && s++) - { - char *opts[]={"back","fore","font","title","icon","frame","padding", - "swallow","action","container","end","nosize","size", - "panel", "left", "right", "center", - NULL}; - s = trimleft(s); - while(*s && *s!=')') - { - if((*s>='0' && *s<='9') || *s=='+' || *s=='-') - { - char *geom; - int x,y,w,h,flags; - geom=seekright(&s); - if (geom) - { - flags=XParseGeometry(geom, &x, &y, &w, &h); - if(flags&WidthValue) - b->BWidth=w; - if(flags&HeightValue) - b->BHeight=h; - if(flags&XValue) - { - b->BPosX=x; - b->flags|=b_PosFixed; - } - if(flags&YValue) - { - b->BPosY=y; - b->flags|=b_PosFixed; - } - if(flags&XNegative) - b->BPosX=-1-x; - if(flags&YNegative) - b->BPosY=-1-y; - free(geom); - } - s = trimleft(s); - continue; - } - if(*s==',' && s++) - s = trimleft(s); - switch(GetTokenIndex(s,opts,-1,&s)) - { - case 0: /* Back */ - s = trimleft(s); - if(*s=='(' && s++) - if(ParseBack(&s)) - b->flags|=b_IconBack; - if(b->flags&b_Back && b->back) free(b->back); - b->back=seekright(&s); - if(b->back) - b->flags|=b_Back; - else - b->flags&=~(b_IconBack|b_Back); - break; - - case 1: /* Fore */ - if(b->flags&b_Fore && b->fore) free(b->fore); - b->fore=seekright(&s); - if(b->fore) - b->flags|=b_Fore; - else - b->flags&=~b_Fore; - break; - - case 2: /* Font */ - if(b->flags&b_Font && b->font_string) free(b->font_string); - b->font_string=seekright(&s); - if(b->font_string) - b->flags|=b_Font; - else - b->flags&=~b_Font; - break; - - /* --------------------------- Title ------------------------- */ - - case 3: /* Title */ - s = trimleft(s); - if(*s=='(' && s++) - { - b->justify=0; - b->justify_mask=0; - ParseTitle(&s,&b->justify,&b->justify_mask); - if(b->justify_mask) - b->flags|=b_Justify; - } - t=seekright(&s); - if(t && *t && (t[0]!='-' || t[1]!=0)) - { - if (b->title) - free(b->title); - b->title=t; + button_info *b, *ub = *uberb; + int i, j; + char *t, *o; + b = alloc_button(ub, (ub->c->num_buttons)++); + s = trimleft(s); + + if (*s == '(' && s++) { + char *opts[] = {"back", "fore", "font", "title", "icon", + "frame", "padding", "swallow", "action", "container", "end", + "nosize", "size", "panel", "left", "right", "center", NULL}; + s = trimleft(s); + while (*s && *s != ')') { + if ((*s >= '0' && *s <= '9') || *s == '+' || + *s == '-') { + char *geom; + int x, y, w, h, flags; + geom = seekright(&s); + if (geom) { + flags = XParseGeometry( + geom, &x, &y, &w, &h); + if (flags & WidthValue) + b->BWidth = w; + if (flags & HeightValue) + b->BHeight = h; + if (flags & XValue) { + b->BPosX = x; + b->flags |= b_PosFixed; + } + if (flags & YValue) { + b->BPosY = y; + b->flags |= b_PosFixed; + } + if (flags & XNegative) + b->BPosX = -1 - x; + if (flags & YNegative) + b->BPosY = -1 - y; + free(geom); + } + s = trimleft(s); + continue; + } + if (*s == ',' && s++) + s = trimleft(s); + switch (GetTokenIndex(s, opts, -1, &s)) { + case 0: /* Back */ + s = trimleft(s); + if (*s == '(' && s++) + if (ParseBack(&s)) + b->flags |= b_IconBack; + if (b->flags & b_Back && b->back) + free(b->back); + b->back = seekright(&s); + if (b->back) + b->flags |= b_Back; + else + b->flags &= ~(b_IconBack | b_Back); + break; + + case 1: /* Fore */ + if (b->flags & b_Fore && b->fore) + free(b->fore); + b->fore = seekright(&s); + if (b->fore) + b->flags |= b_Fore; + else + b->flags &= ~b_Fore; + break; + + case 2: /* Font */ + if (b->flags & b_Font && b->font_string) + free(b->font_string); + b->font_string = seekright(&s); + if (b->font_string) + b->flags |= b_Font; + else + b->flags &= ~b_Font; + break; + + /* --------------------------- Title + * ------------------------- */ + + case 3: /* Title */ + s = trimleft(s); + if (*s == '(' && s++) { + b->justify = 0; + b->justify_mask = 0; + ParseTitle( + &s, &b->justify, &b->justify_mask); + if (b->justify_mask) + b->flags |= b_Justify; + } + t = seekright(&s); + if (t && *t && (t[0] != '-' || t[1] != 0)) { + if (b->title) + free(b->title); + b->title = t; #ifdef DEBUG_PARSER - fprintf(stderr,"PARSE: Title \"%s\"\n",b->title); + fprintf(stderr, "PARSE: Title \"%s\"\n", + b->title); #endif - b->flags|=b_Title; - } - else - { - fprintf(stderr,"%s: Missing title argument\n",MyName); - if(t)free(t); + b->flags |= b_Title; + } else { + fprintf(stderr, + "%s: Missing title argument\n", + MyName); + if (t) + free(t); + } + break; + + /* ---------------------------- icon + * ------------------------- */ + + case 4: /* Icon */ + t = seekright(&s); + if (t && *t && (t[0] != '-' || t[1] != 0)) { + if (b->icon_file) + free(b->icon_file); + b->icon_file = t; + b->IconWin = None; + b->flags |= b_Icon; + } else { + fprintf(stderr, + "%s: Missing icon argument\n", + MyName); + if (t) + free(t); + } + break; + + /* --------------------------- frame + * ------------------------- */ + + case 5: /* Frame */ + i = strtol(s, &t, 10); + if (t > s) { + b->flags |= b_Frame; + b->framew = i; + s = t; + } else + fprintf(stderr, + "%s: Illegal frame argument\n", + MyName); + break; + + /* -------------------------- padding + * ------------------------ */ + + case 6: /* Padding */ + i = strtol(s, &t, 10); + if (t > s) { + b->xpad = b->ypad = i; + b->flags |= b_Padding; + s = t; + i = strtol(s, &t, 10); + if (t > s) { + b->ypad = i; + s = t; + } + } else + fprintf(stderr, + "%s: Illegal padding argument\n", + MyName); + break; + + /* -------------------------- swallow + * ------------------------ */ + + case 7: /* Swallow */ + s = trimleft(s); + b->swallow = 0; + b->swallow_mask = 0; + if (*s == '(' && s++) + ParseSwallow( + &s, &b->swallow, &b->swallow_mask); + t = seekright(&s); + o = seekright_command(&s); + if (t) { + if (b->hangon) + free(b->hangon); + b->hangon = t; + b->flags |= b_Hangon; + b->flags |= b_Swallow; + b->swallow |= 1; + if (!(b->swallow & b_NoHints)) + b->hints = + (XSizeHints *)xmalloc( + sizeof(XSizeHints)); + if (o) { + if (!(buttonSwallow(b) & + b_UseOld)) + SendText(fd, o, 0); + if (b->spawn) + free(b->spawn); + b->spawn = + o; /* Might be needed if + respawning sometime */ + } + } else { + fprintf(stderr, + "%s: Missing swallow argument\n", + MyName); + if (t) + free(t); + if (o) + free(o); + } + break; + + /* --------------------------- action + * ------------------------ */ + + case 8: /* Action */ + s = trimleft(s); + i = 0; + if (*s == '(') { + s++; + if (strncasecmp(s, "mouse", 5) != 0) { + fprintf(stderr, + "%s: Couldn't parse " + "action\n", + MyName); + } + s += 5; + i = strtol(s, &t, 10); + s = t; + while (*s && *s != ')') + s++; + if (*s == ')') + s++; + } + s = GetQuotedString( + s, &t, ",)", NULL, NULL, NULL); + if (t) { + AddButtonAction(b, i, t); + free(t); + } else + fprintf(stderr, + "%s: Missing action argument\n", + MyName); + break; + + /* -------------------------- container + * ---------------------- */ + + case 9: /* Container */ + b->flags &= b_Frame | b_Back | b_Fore | + b_Padding | b_Action; + MakeContainer(b); + *uberb = b; + s = trimleft(s); + if (*s == '(' && s++) + ParseContainer(&s, b); + break; + + case 10: /* End */ + *uberb = ub->parent; + ub->c->buttons[--(ub->c->num_buttons)] = NULL; + if (!ub->parent) { + fprintf(stderr, + "%s: Unmatched END in config " + "file\n", + MyName); + exit(1); + } + break; + + case 11: /* NoSize */ + b->flags |= b_Size; + b->minx = b->miny = 0; + break; + + case 12: /* Size */ + i = strtol(s, &t, 10); + j = strtol(t, &o, 10); + if (t > s && o > t) { + b->minx = i; + b->miny = j; + b->flags |= b_Size; + s = o; + } else + fprintf(stderr, + "%s: Illegal size arguments\n", + MyName); + break; + + /* --------------------------- panel + * ------------------------ */ + + case 13: /* Panel */ + s = trimleft(s); + if (*s == '(') { + s++; + t = seekright(&s); + if (terminator != ')') + while (*s && *s != ')') + s++; + if (*s == ')') + s++; + if (strncasecmp(t, "right", 5) == 0) + t = "panel-r"; + else if (strncasecmp(t, "left", 4) == 0) + t = "panel-l"; + else if (strncasecmp(t, "down", 4) == 0) + t = "panel-d"; + else if (strncasecmp( + t, "geometry", 8) == 0) + t = "panel-g"; + else + t = "panel-u"; + } else + t = "panel-u"; + AddButtonAction(b, 0, t); + + b->IconWin = None; + t = seekright(&s); + b->hangon = + (t) ? t : + strdup(""); /* which panel to popup */ + break; + + case 14: /* Left */ + b->flags |= b_Left; + b->flags &= ~b_Right; + break; + + case 15: /* Right */ + b->flags |= b_Right; + b->flags &= ~b_Left; + break; + + case 16: /* Center */ + b->flags &= ~(b_Right | b_Left); + break; + + default: + t = seekright(&s); + fprintf(stderr, + "%s: Illegal button option \"%s\"\n", + MyName, (t) ? t : ""); + if (t) + free(t); + break; + } + s = trimleft(s); } - break; - - /* ---------------------------- icon ------------------------- */ - - case 4: /* Icon */ - t=seekright(&s); - if(t && *t && (t[0] != '-' || t[1] != 0)) - { - if (b->icon_file) - free(b->icon_file); - b->icon_file=t; - b->IconWin=None; - b->flags|=b_Icon; + if (s && *s) { + s++; + s = trimleft(s); } - else - { - fprintf(stderr,"%s: Missing icon argument\n",MyName); - if(t)free(t); - } - break; + } - /* --------------------------- frame ------------------------- */ + /* get title and iconname */ + if (!(b->flags & b_Title)) { + b->title = seekright(&s); + if (b->title && *b->title && + ((b->title)[0] != '-' || (b->title)[1] != 0)) + b->flags |= b_Title; + else if (b->title) + free(b->title); + } else { + char *temp; + temp = seekright(&s); + if (temp) + free(temp); + } - case 5: /* Frame */ - i=strtol(s,&t,10); - if(t>s) - { - b->flags|=b_Frame; - b->framew=i; - s=t; - } - else - fprintf(stderr,"%s: Illegal frame argument\n",MyName); - break; - - /* -------------------------- padding ------------------------ */ - - case 6: /* Padding */ - i=strtol(s,&t,10); - if(t>s) - { - b->xpad=b->ypad=i; - b->flags |= b_Padding; - s=t; - i=strtol(s,&t,10); - if(t>s) - { - b->ypad=i; - s=t; - } - } - else - fprintf(stderr,"%s: Illegal padding argument\n",MyName); - break; - - /* -------------------------- swallow ------------------------ */ - - case 7: /* Swallow */ - s = trimleft(s); - b->swallow=0; - b->swallow_mask=0; - if(*s=='(' && s++) - ParseSwallow(&s,&b->swallow,&b->swallow_mask); - t=seekright(&s); - o=seekright(&s); - if(t) - { - if (b->hangon) - free(b->hangon); - b->hangon=t; - b->flags|=b_Hangon; - b->flags|=b_Swallow; - b->swallow|=1; - if(!(b->swallow&b_NoHints)) - b->hints=(XSizeHints*)mymalloc(sizeof(XSizeHints)); - if(o) - { - if(!(buttonSwallow(b)&b_UseOld)) - SendText(fd,o,0); - if (b->spawn) - free(b->spawn); - b->spawn=o; /* Might be needed if respawning sometime */ - } - } - else - { - fprintf(stderr,"%s: Missing swallow argument\n",MyName); - if(t)free(t); - if(o)free(o); - } - break; - - /* --------------------------- action ------------------------ */ - - case 8: /* Action */ - s = trimleft(s); - i=0; - if(*s=='(') - { - s++; - if(strncasecmp(s,"mouse",5)!=0) - { - fprintf(stderr,"%s: Couldn't parse action\n",MyName); - } - s+=5; - i=strtol(s,&t,10); - s=t; - while(*s && *s!=')') - s++; - if(*s==')')s++; - } - s = GetQuotedString(s, &t, ",)", NULL, NULL, NULL); - if(t) - { - AddButtonAction(b,i,t); - free(t); + if (!(b->flags & b_Icon)) { + b->icon_file = seekright(&s); + if (b->icon_file && b->icon_file && + ((b->icon_file)[0] != '-' || (b->icon_file)[1] != 0)) { + b->flags |= b_Icon; + b->IconWin = None; + } else if (b->icon_file) + free(b->icon_file); + } else { + char *temp; + temp = seekright(&s); + if (temp) + free(temp); + } + + s = trimleft(s); + + /* Swallow hangon command */ + if (strncasecmp(s, "swallow", 7) == 0) { + if (b->flags & b_Swallow) { + fprintf(stderr, + "%s: Illegal with both old and new swallow!\n", + MyName); + exit(1); } - else - fprintf(stderr,"%s: Missing action argument\n",MyName); - break; - - /* -------------------------- container ---------------------- */ - - case 9: /* Container */ - b->flags&=b_Frame|b_Back|b_Fore|b_Padding|b_Action; - MakeContainer(b); - *uberb=b; - s = trimleft(s); - if(*s=='(' && s++) - ParseContainer(&s,b); - break; - - case 10: /* End */ - *uberb=ub->parent; - ub->c->buttons[--(ub->c->num_buttons)]=NULL; - if(!ub->parent) - { - fprintf(stderr,"%s: Unmatched END in config file\n",MyName); - exit(1); + s += 7; + /* + * Swallow old 'swallowmodule' command + */ + if (strncasecmp(s, "module", 6) == 0) { + s += 6; } - break; - - case 11: /* NoSize */ - b->flags|=b_Size; - b->minx=b->miny=0; - break; - - case 12: /* Size */ - i=strtol(s,&t,10); - j=strtol(t,&o,10); - if(t>s && o>t) - { - b->minx=i; - b->miny=j; - b->flags|=b_Size; - s=o; + if (b->hangon) + free(b->hangon); + b->hangon = seekright(&s); + if (!b->hangon) + b->hangon = strdup(""); + b->flags |= (b_Swallow | b_Hangon); + b->swallow |= 1; + s = trimleft(s); + if (!(b->swallow & b_NoHints)) + b->hints = (XSizeHints *)xmalloc(sizeof(XSizeHints)); + if (*s) { + if (!(buttonSwallow(b) & b_UseOld)) + SendText(fd, s, 0); + b->spawn = strdup(s); } - else - fprintf(stderr,"%s: Illegal size arguments\n",MyName); - break; - - /* --------------------------- panel ------------------------ */ - - case 13: /* Panel */ - s = trimleft(s); - if(*s=='(') - { - s++; - t = seekright(&s); - if (terminator != ')') - while(*s && *s!=')') - s++; - if(*s==')') - s++; - if (strncasecmp(t,"right",5)==0) - t = "panel-r"; - else if (strncasecmp(t,"left" ,4)==0) - t = "panel-l"; - else if (strncasecmp(t,"down" ,4)==0) - t = "panel-d"; - else if (strncasecmp(t,"geometry",8)==0) - t = "panel-g"; - else - t = "panel-u"; - } - else - t = "panel-u"; - AddButtonAction(b, 0, t); - - b->IconWin = None; - t = seekright(&s); - b->hangon = (t)? t : strdup(""); /* which panel to popup */ - break; - - case 14: /* Left */ - b->flags |= b_Left; - b->flags &= ~b_Right; - break; - - case 15: /* Right */ - b->flags |= b_Right; - b->flags &= ~b_Left; - break; - - case 16: /* Center */ - b->flags &= ~(b_Right|b_Left); - break; - - default: - t=seekright(&s); - fprintf(stderr,"%s: Illegal button option \"%s\"\n",MyName, - (t)?t:""); - if (t) - free(t); - break; - } - s = trimleft(s); - } - if (s && *s) - { - s++; - s = trimleft(s); - } - } - - /* get title and iconname */ - if(!(b->flags&b_Title)) - { - b->title=seekright(&s); - if(b->title && *b->title && ((b->title)[0]!='-'||(b->title)[1]!=0)) - b->flags |= b_Title; - else - if(b->title)free(b->title); - } - else - { - char *temp; - temp = seekright(&s); - if (temp) - free(temp); - } - - if(!(b->flags&b_Icon)) - { - b->icon_file=seekright(&s); - if(b->icon_file && b->icon_file && - ((b->icon_file)[0]!='-'||(b->icon_file)[1]!=0)) - { - b->flags|=b_Icon; - b->IconWin=None; - } - else - if(b->icon_file)free(b->icon_file); - } - else - { - char *temp; - temp = seekright(&s); - if (temp) - free(temp); - } - - s = trimleft(s); - - /* Swallow hangon command */ - if(strncasecmp(s,"swallow",7)==0) - { - if(b->flags&b_Swallow) - { - fprintf(stderr,"%s: Illegal with both old and new swallow!\n", - MyName); - exit(1); - } - s+=7; - /* - * Swallow old 'swallowmodule' command - */ - if (strncasecmp(s,"module",6)==0) - { - s+=6; - } - if (b->hangon) - free(b->hangon); - b->hangon=seekright(&s); - if (!b->hangon) - b->hangon = strdup(""); - b->flags|=(b_Swallow|b_Hangon); - b->swallow|=1; - s = trimleft(s); - if(!(b->swallow&b_NoHints)) - b->hints=(XSizeHints*)mymalloc(sizeof(XSizeHints)); - if(*s) - { - if(!(buttonSwallow(b)&b_UseOld)) - SendText(fd,s,0); - b->spawn=strdup(s); - } - } - else if(*s) - AddButtonAction(b,0,s); - return; + } else if (*s) + AddButtonAction(b, 0, s); + return; } /** *** ParseConfigLine **/ -void ParseConfigLine(button_info **ubb,char *s) +void +ParseConfigLine(button_info **ubb, char *s) { - button_info *ub=*ubb; - char *opts[]={"geometry","font","padding","columns","rows","back","fore", - "frame","file","pixmap","panel","boxsize",NULL}; - int i,j,k; - - switch(GetTokenIndex(s,opts,-1,&s)) - { - case 0:/* Geometry */ - { - char geom[64]; - int flags,g_x,g_y; - unsigned int width,height; - i=sscanf(s,"%63s",geom); - if(i==1) - { - flags=XParseGeometry(geom,&g_x,&g_y,&width,&height); - UberButton->w = 0; - UberButton->h = 0; - if(flags&WidthValue) - w=width; - if(flags&HeightValue) - h=height; - if(flags&XValue) - UberButton->x = g_x; - if(flags&YValue) - UberButton->y = g_y; - if(flags&XNegative) - UberButton->w = 1; - if(flags&YNegative) - UberButton->h = 1; - } - break; - } - case 1:/* Font */ - CopyString(&ub->c->font_string,s); - break; - case 2:/* Padding */ - i=sscanf(s,"%d %d",&j,&k); - if(i>0) ub->c->xpad=ub->c->ypad=j; - if(i>1) ub->c->ypad=k; - break; - case 3:/* Columns */ - i=sscanf(s,"%d",&j); - if(i>0) ub->c->num_columns=j; - break; - case 4:/* Rows */ - i=sscanf(s,"%d",&j); - if(i>0) ub->c->num_rows=j; - break; - case 5:/* Back */ - CopyString(&(ub->c->back),s); - break; - case 6:/* Fore */ - CopyString(&(ub->c->fore),s); - break; - case 7:/* Frame */ - i=sscanf(s,"%d",&j); - if(i>0) ub->c->framew=j; - break; - case 8:/* File */ - s = trimleft(s); - if (config_file) - free(config_file); - config_file=seekright(&s); - break; - case 9:/* Pixmap */ - s = trimleft(s); - if (strncasecmp(s,"none",4)==0) - ub->c->flags|=b_TransBack; - else - CopyString(&(ub->c->back_file),s); - ub->c->flags|=b_IconBack; - break; - case 10:/* Panel */ - s = trimleft(s); - CurrentPanel->next = (panel_info *) mymalloc(sizeof(panel_info)); - CurrentPanel = CurrentPanel->next; - CurrentPanel->next = NULL; - CurrentPanel->uber = UberButton - = (button_info *) mymalloc(sizeof(button_info)); - if (UberButton->title) - free(UberButton->title); - UberButton->title = seekright(&s); - UberButton->flags = 0; - UberButton->parent = NULL; - UberButton->BWidth = 1; - UberButton->BHeight = 1; - UberButton->swallow = 0; /* subpanel is hidden initially */ - MakeContainer(UberButton); - ub = *ubb = UberButton; - break; - case 11: /* BoxSize */ - ParseBoxSize(&s, &ub->c->flags); - break; - default: - s = trimleft(s); - match_string(ubb,s); - break; - } + button_info *ub = *ubb; + char *opts[] = {"geometry", "font", "padding", "columns", "rows", + "back", "fore", "frame", "file", "pixmap", "panel", "boxsize", + NULL}; + int i, j, k; + + switch (GetTokenIndex(s, opts, -1, &s)) { + case 0: /* Geometry */ { + char geom[64]; + int flags, g_x, g_y; + unsigned int width, height; + i = sscanf(s, "%63s", geom); + if (i == 1) { + flags = + XParseGeometry(geom, &g_x, &g_y, &width, &height); + w = -1; + h = -1; + CurrentPanel->geom_w = -1; + CurrentPanel->geom_h = -1; + UberButton->w = 0; + UberButton->h = 0; + UberButton->x = -30000; + UberButton->y = -30000; + if (flags & WidthValue) { + w = (int)width; + CurrentPanel->geom_w = (int)width; + } + if (flags & HeightValue) { + h = (int)height; + CurrentPanel->geom_h = (int)height; + } + if (flags & XValue) + UberButton->x = g_x; + if (flags & YValue) + UberButton->y = g_y; + if (flags & XNegative) + UberButton->w = 1; + if (flags & YNegative) + UberButton->h = 1; + } + break; + } + case 1: /* Font */ + CopyString(&ub->c->font_string, s); + break; + case 2: /* Padding */ + i = sscanf(s, "%d %d", &j, &k); + if (i > 0) + ub->c->xpad = ub->c->ypad = j; + if (i > 1) + ub->c->ypad = k; + break; + case 3: /* Columns */ + i = sscanf(s, "%d", &j); + if (i > 0) + ub->c->num_columns = j; + break; + case 4: /* Rows */ + i = sscanf(s, "%d", &j); + if (i > 0) + ub->c->num_rows = j; + break; + case 5: /* Back */ + CopyString(&(ub->c->back), s); + break; + case 6: /* Fore */ + CopyString(&(ub->c->fore), s); + break; + case 7: /* Frame */ + i = sscanf(s, "%d", &j); + if (i > 0) + ub->c->framew = j; + break; + case 8: /* File */ + s = trimleft(s); + if (config_file) + free(config_file); + config_file = seekright(&s); + break; + case 9: /* Pixmap */ + s = trimleft(s); + if (strncasecmp(s, "none", 4) == 0) + ub->c->flags |= b_TransBack; + else + CopyString(&(ub->c->back_file), s); + ub->c->flags |= b_IconBack; + break; + case 10: /* Panel */ + s = trimleft(s); + CurrentPanel->next = (panel_info *)xmalloc(sizeof(panel_info)); + CurrentPanel = CurrentPanel->next; + memset(CurrentPanel, 0, sizeof(panel_info)); + CurrentPanel->geom_w = -1; + CurrentPanel->geom_h = -1; + CurrentPanel->next = NULL; + CurrentPanel->uber = UberButton = + (button_info *)xmalloc(sizeof(button_info)); + memset(UberButton, 0, sizeof(button_info)); + UberButton->title = seekright(&s); + UberButton->flags = 0; + UberButton->parent = NULL; + UberButton->BWidth = 1; + UberButton->BHeight = 1; + UberButton->swallow = 0; /* subpanel is hidden initially */ + UberButton->x = -30000; + UberButton->y = -30000; + MakeContainer(UberButton); + ub = *ubb = UberButton; + break; + case 11: /* BoxSize */ + ParseBoxSize(&s, &ub->c->flags); + break; + default: + s = trimleft(s); + match_string(ubb, s); + break; + } } /** *** ParseConfigFile() *** Parses optional separate configuration file for FvwmButtons **/ -void ParseConfigFile(button_info *ub) +void +ParseConfigFile(button_info *ub) { - char s[1024],*t; - FILE *f=fopen(config_file,"r"); - int l; - if(!f) - { - fprintf(stderr,"%s: Couldn't open config file %s\n",MyName,config_file); - return; - } - - while (fgets(s, 1023, f)) - { - /* Allow for line continuation: */ - while ((l=strlen(s)) < sizeof(s) - && l>=2 && s[l-1]=='\n' && s[l-2]=='\\') - fgets(s+l-2, sizeof(s)-l, f); - - /* And comments: */ - t=s; - while(*t) - { - if(*t=='#' && (t==s || *(t-1)!='\\')) - { - *t=0; - break; - } - t++; + char s[1024], *t; + FILE *f = fopen(config_file, "r"); + int l; + if (!f) { + fprintf(stderr, "%s: Couldn't open config file %s\n", MyName, + config_file); + return; } - t = s; - t = trimleft(t); - if(*t) - ParseConfigLine(&ub,t); - } - fclose(f); + while (fgets(s, 1023, f)) { + /* Allow for line continuation: */ + while ((l = strlen(s)) < sizeof(s) && l >= 2 && + s[l - 1] == '\n' && s[l - 2] == '\\') + fgets(s + l - 2, sizeof(s) - l, f); + + /* And comments: */ + t = s; + while (*t) { + if (*t == '#' && (t == s || *(t - 1) != '\\')) { + *t = 0; + break; + } + t++; + } + t = s; + t = trimleft(t); + if (*t) + ParseConfigLine(&ub, t); + } + + fclose(f); } -extern int save_color_limit; /* global for xpm color limiting */ +extern int save_color_limit; /* global for xpm color limiting */ /** *** ParseOptions() **/ -void ParseOptions(button_info *ub) +void +ParseOptions(button_info *ub) { - char *s; - char *items[]={"iconpath","pixmappath","colorlimit",NULL,NULL}; - - items[3]=mymalloc(strlen(MyName)+2); - sprintf(items[3],"*%s",MyName); - - GetConfigLine(fd,&s); - while(s && s[0]) - { - switch(GetTokenIndex(s,items,-1,&s)) - { - case -1: - break; - case 0: - if (iconPath) - free(iconPath); - CopyString(&iconPath,s); - break; - case 1: - if (pixmapPath) - free(pixmapPath); - CopyString(&pixmapPath,s); - break; - case 2: /* colorlimit */ - sscanf(s,"%d",&save_color_limit); - break; - case 3: - if(s && s[0] && !config_file) - ParseConfigLine(&ub,s); + char *s; + char *items[] = {"iconpath", "pixmappath", "colorlimit", NULL, NULL}; + + size_t name_len = strlen(MyName); + items[3] = xmalloc(name_len + 2); + snprintf(items[3], name_len + 2, "*%s", MyName); + + GetConfigLine(fd, &s); + while (s && s[0]) { + switch (GetTokenIndex(s, items, -1, &s)) { + case -1: + break; + case 0: + if (iconPath) + free(iconPath); + CopyString(&iconPath, s); + break; + case 1: + if (pixmapPath) + free(pixmapPath); + CopyString(&pixmapPath, s); + break; + case 2: /* colorlimit */ + sscanf(s, "%d", &save_color_limit); + break; + case 3: + if (s && s[0] && !config_file) + ParseConfigLine(&ub, s); + } + GetConfigLine(fd, &s); } - GetConfigLine(fd,&s); - } - if(config_file) - ParseConfigFile(ub); + if (config_file) + ParseConfigFile(ub); - free(items[3]); - return; + free(items[3]); + return; } Index: fvwm/modules/FvwmButtons/parse.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/parse.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/parse.h --- fvwm/modules/FvwmButtons/parse.h +++ fvwm/modules/FvwmButtons/parse.h @@ -12,6 +12,4 @@ */ -void ParseOptions(button_info*); - - +void ParseOptions(button_info *); Index: fvwm/modules/FvwmCpp/FvwmCpp.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmCpp/FvwmCpp.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmCpp/FvwmCpp.1 --- fvwm/modules/FvwmCpp/FvwmCpp.1 +++ fvwm/modules/FvwmCpp/FvwmCpp.1 @@ -14,52 +14,43 @@ .if n .sp 1 .if t .sp .5 .. -.TH FvwmCpp 1 12/12/94 2.0 +.TH FVWMCPP 1 "December 12, 1994" "2.0" "FVWM Modules" .UC .SH NAME FvwmCpp \- the FVWM Cpp pre-processor .SH SYNOPSIS FvwmCpp is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION When called, this module will attempt to have /usr/lib/cpp pre-process the file specified in its invocation, and then have fvwm read the resulting file. - .SH INVOCATION FvwmCpp can be invoked by inserting the line 'FvwmCpp' in the .fvwmrc file. It can also be called from a menu or mouse binding. If the user wants his entire .fvwmrc file pre-processed with FvwmCpp, then fvwm should be invoked as: - .EX fvwm2 -cmd "FvwmCpp .fvwmrc" .EE - +.PP Some options can be specified on the command line: .TP -cppopt \fIoption\fP Lets you pass an option to the cpp program. Not really needed as any unknown options will be passed on automatically. - .TP -cppprog \fIname\fP Instead of invoking "/usr/lib/cpp", fvwm will invoke \fIname\fP. - .TP -outfile \fIfilename\fP Instead of creating a random unique name for the temporary file for the preprocessed rc file, this option will let you specify the name of the temporary file it will create. - .IP -debug -Causes the temporary file create by Cpp to -be retained. This file is usually called "/tmp/fvwmrcXXXXXXXXXX" - - +Causes the temporary file created by Cpp to be retained. This file is usually +called "/tmp/fvwmrcXXXXXXXXXX". .SH CONFIGURATION OPTIONS FvwmCpp defines some values for use in the pre-processor file: - .IP TWM_TYPE Always set to "fvwm". .IP SERVERHOST @@ -104,9 +95,7 @@ configure.h at compile time. .IP FVWM_MODULEDIR The directory where fvwm looks for .fvwmrc and modules by default, as determined at compile time. - .SH EXAMPLE PROLOG - .EX #define TWM_TYPE fvwm #define SERVERHOST spx20 @@ -126,17 +115,11 @@ determined at compile time. #define PLANES 8 #define BITS_PER_RGB 8 #define CLASS PseudoColor -#define COLOR Yes #define FVWM_VERSION 2.0 pl 1 #define OPTIONS SHAPE XPM Cpp #define FVWM_MODULEDIR /local/homes/dsp/nation/modules - .EE - .SH BUGS -Module configurations do not become active until fvwm2 has restarted -if you use FvwmCpp on startup. FvwmCpp creates a temporary file -and passes this to fvwm2, so you would have to edit this file too. There are some problems with comments in your .fvwmrc file. The comment sign # is misinterpreted by the preprocessor. This has usually no impact on functionality but generates @@ -161,7 +144,6 @@ and not .EX "Exec "ls" -l" (one word). .EE - .SH AUTHOR FvwmCpp is the result of a random bit mutation on a hard disk, -presumably a result of a cosmic-ray or some such thing. +presumably a result of a cosmic-ray or some such thing. Index: fvwm/modules/FvwmCpp/FvwmCpp.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmCpp/FvwmCpp.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmCpp/FvwmCpp.c --- fvwm/modules/FvwmCpp/FvwmCpp.c +++ fvwm/modules/FvwmCpp/FvwmCpp.c @@ -3,45 +3,44 @@ * by Robert Nation * * Copyright 1994, Robert Nation - * No guarantees or warantees or anything + * No guarantees or warantees or anything * are provided or implied in any way whatsoever. Use this program at your * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ #define TRUE 1 -#define FALSE 0 +#define FALSE 0 -#include "config.h" +#include "FvwmCpp.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include #include -#include +#include +#include +#include +#include +#include +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "../../fvwm/module.h" - -#include "FvwmCpp.h" #include "../../libs/fvwmlib.h" -#include -#include -#include -#define Resolution(pixels, mm) ((((pixels) * 100000 / (mm)) + 50) / 100) +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" +#define Resolution(pixels, mm) ((((pixels) * 100000 / (mm)) + 50) / 100) char *MyName; int fd[2]; @@ -52,16 +51,18 @@ int ScreenWidth, ScreenHeight; int Mscreen; long Vx, Vy; -static char *MkDef(char *name, char *def); -static char *MkNum(char *name,int def); -static char *cpp_defs(Display *display, const char *host, char *m4_options, char *config_file); +static char *MkDef(const char *name, const char *def); +static char *MkNum(const char *name, int def); +static int cpp_process(Display *display, const char *host, char *options, + const char *config_file, int keep_output); +static int is_cpp_linemarker(const char *line); #define MAXHOSTNAME 255 #define EXTRA 20 -char *cpp_prog = FVWM_CPP; /* Name of the cpp program */ +char *cpp_prog = FVWM_CPP; /* Name of the cpp program */ char cpp_options[BUFSIZ]; -char cpp_outfile[BUFSIZ]=""; +char cpp_outfile[BUFSIZ] = ""; /*********************************************************************** * @@ -70,294 +71,433 @@ char cpp_outfile[BUFSIZ]=""; * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - Display *dpy; /* which display are we talking to */ - char *temp, *s; - char *display_name = NULL; - char *filename = NULL; - char *tmp_file, read_string[80],delete_string[80]; - int i,cpp_debug = 0; - - strcpy(cpp_options,""); - - /* Record the program name for error messages */ - temp = argv[0]; - - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - - if(argc < 6) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - /* Open the X display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - - - Mscreen= DefaultScreen(dpy); - ScreenHeight = DisplayHeight(dpy,Mscreen); - ScreenWidth = DisplayWidth(dpy,Mscreen); - - /* We should exit if our fvwm pipes die */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - for(i=6;i", sizeof(options)); - strlcat(options, tmp_name, sizeof(options)); - - tmpf = popen(options, "w"); - if (tmpf == NULL) { - perror("Cannot open pipe to cpp"); - exit(0377); - } - - gethostname(client,MAXHOSTNAME); - - getostype (ostype, sizeof ostype); - - hostname = gethostbyname(client); - strlcpy(server, XDisplayName(host), sizeof(server)); - colon = strchr(server, ':'); - if (colon != NULL) *colon = '\0'; - if ((server[0] == '\0') || (!strcmp(server, "unix"))) - strlcpy(server, client, sizeof(server)); /* must be connected to :0 or unix:0 */ - - /* TWM_TYPE is fvwm, for completeness */ - - fputs(MkDef("TWM_TYPE", "fvwm"), tmpf); - - /* The machine running the X server */ - fputs(MkDef("SERVERHOST", server), tmpf); - /* The machine running the window manager process */ - fputs(MkDef("CLIENTHOST", client), tmpf); - if (hostname) - fputs(MkDef("HOSTNAME", (char *)hostname->h_name), tmpf); - else - fputs(MkDef("HOSTNAME", (char *)client), tmpf); - - fputs(MkDef("OSTYPE", ostype), tmpf); - - pwent=getpwuid(geteuid()); - fputs(MkDef("USER", pwent->pw_name), tmpf); - - fputs(MkDef("HOME", getenv("HOME")), tmpf); - fputs(MkNum("VERSION", ProtocolVersion(display)), tmpf); - fputs(MkNum("REVISION", ProtocolRevision(display)), tmpf); - fputs(MkDef("VENDOR", ServerVendor(display)), tmpf); - fputs(MkNum("RELEASE", VendorRelease(display)), tmpf); - screen = ScreenOfDisplay(display, Mscreen); - visual = DefaultVisualOfScreen(screen); - fputs(MkNum("WIDTH", DisplayWidth(display,Mscreen)), tmpf); - fputs(MkNum("HEIGHT", DisplayHeight(display,Mscreen)), tmpf); - - fputs(MkNum("X_RESOLUTION",Resolution(screen->width,screen->mwidth)),tmpf); - fputs(MkNum("Y_RESOLUTION",Resolution(screen->height,screen->mheight)),tmpf); - fputs(MkNum("PLANES",DisplayPlanes(display, Mscreen)), tmpf); - - fputs(MkNum("BITS_PER_RGB", visual->bits_per_rgb), tmpf); - fputs(MkNum("SCREEN", Mscreen), tmpf); - - switch(visual->class) - { - case(StaticGray): - vc = "StaticGray"; - break; - case(GrayScale): - vc = "GrayScale"; - break; - case(StaticColor): - vc = "StaticColor"; - break; - case(PseudoColor): - vc = "PseudoColor"; - break; - case(TrueColor): - vc = "TrueColor"; - break; - case(DirectColor): - vc = "DirectColor"; - break; - default: - vc = "NonStandard"; - break; - } - - fputs(MkDef("CLASS", vc), tmpf); - if (visual->class != StaticGray && visual->class != GrayScale) - fputs(MkDef("COLOR", "Yes"), tmpf); - else - fputs(MkDef("COLOR", "No"), tmpf); - fputs(MkDef("FVWM_VERSION", VERSION), tmpf); - - /* Add options together */ - *options = '\0'; -#ifdef SHAPE - strcat(options, "SHAPE "); -#endif -#ifdef XPM - strcat(options, "XPM "); -#endif + Screen *screen; + Visual *visual; + char client[MAXHOSTNAME], server[MAXHOSTNAME], *colon; + char ostype[BUFSIZ]; + char feature_opts[BUFSIZ]; + struct hostent *hostname; + char *vc; + struct passwd *pwent; + FILE *cpp_in = NULL; + FILE *cpp_out = NULL; + FILE *mirror = NULL; + int to_child[2]; + int from_child[2]; + pid_t pid; + int status; + char command[2 * BUFSIZ]; + char tmp_name[BUFSIZ]; + int created_temp = 0; + char kept_path[BUFSIZ]; + size_t line_cap = 1024; + char *linebuf = NULL; + size_t line_len = 0; + unsigned char chunk[BUFSIZ]; + size_t nread; + int appended_newline = 0; + + kept_path[0] = '\0'; + + if (cpp_outfile[0] != '\0') { + mirror = fopen(cpp_outfile, "w"); + if (mirror == NULL) + fprintf(stderr, "%s: unable to open %s for writing\n", + MyName, cpp_outfile); + } else if (keep_output) { + const char *tmpdir = getenv("TMPDIR"); + if (tmpdir == NULL) + tmpdir = "/tmp"; + strlcpy(tmp_name, tmpdir, sizeof(tmp_name)); + strlcat(tmp_name, "/fvwmcppXXXXXXXXXX", sizeof(tmp_name)); + { + int fd_tmp = mkstemp(tmp_name); + if (fd_tmp >= 0) { + mirror = fdopen(fd_tmp, "w"); + if (mirror != NULL) { + strlcpy(kept_path, tmp_name, + sizeof(kept_path)); + created_temp = 1; + } else { + close(fd_tmp); + } + } else { + perror("mkstemp failed in cpp_process"); + } + } + } - strcat(options, "Cpp "); + if (pipe(to_child) == -1 || pipe(from_child) == -1) { + perror("pipe in cpp_process"); + if (mirror) + fclose(mirror); + return -1; + } -#ifdef NO_SAVEUNDERS - strcat(options, "NO_SAVEUNDERS "); -#endif + snprintf(command, sizeof(command), "%s %s", cpp_prog, + (cpp_opts != NULL) ? cpp_opts : ""); + + pid = fork(); + if (pid == -1) { + perror("fork in cpp_process"); + close(to_child[0]); + close(to_child[1]); + close(from_child[0]); + close(from_child[1]); + if (mirror) + fclose(mirror); + return -1; + } - fputs(MkDef("OPTIONS", options), tmpf); + if (pid == 0) { + dup2(to_child[0], STDIN_FILENO); + dup2(from_child[1], STDOUT_FILENO); + close(to_child[0]); + close(to_child[1]); + close(from_child[0]); + close(from_child[1]); + execl("/bin/sh", "sh", "-c", command, (char *)NULL); + _exit(127); + } - fputs(MkDef("FVWM_MODULEDIR", FVWM_MODULEDIR), tmpf); - fputs(MkDef("FVWM_CONFIGDIR", FVWM_CONFIGDIR), tmpf); + close(to_child[0]); + close(from_child[1]); + + cpp_in = fdopen(to_child[1], "w"); + cpp_out = fdopen(from_child[0], "r"); + if (cpp_in == NULL || cpp_out == NULL) { + perror("fdopen in cpp_process"); + if (cpp_in) + fclose(cpp_in); + else + close(to_child[1]); + if (cpp_out) + fclose(cpp_out); + else + close(from_child[0]); + if (mirror) + fclose(mirror); + waitpid(pid, NULL, 0); + return -1; + } - /* - * At this point, we've sent the definitions to cpp. Just include - * the fvwmrc file now. - */ +#define WRITE_DEF(name, value) \ + do { \ + char *tmp__ = MkDef((name), (value)); \ + fputs(tmp__, cpp_in); \ + free(tmp__); \ + } while (0) +#define WRITE_NUM(name, value) \ + do { \ + char *tmp__ = MkNum((name), (value)); \ + fputs(tmp__, cpp_in); \ + free(tmp__); \ + } while (0) + + gethostname(client, MAXHOSTNAME); + getostype(ostype, sizeof ostype); + + hostname = gethostbyname(client); + strlcpy(server, XDisplayName(host), sizeof(server)); + colon = strchr(server, ':'); + if (colon != NULL) + *colon = '\0'; + if ((server[0] == '\0') || (!strcmp(server, "unix"))) + strlcpy(server, client, sizeof(server)); + + WRITE_DEF("TWM_TYPE", "fvwm"); + WRITE_DEF("SERVERHOST", server); + WRITE_DEF("CLIENTHOST", client); + if (hostname) + WRITE_DEF("HOSTNAME", (char *)hostname->h_name); + else + WRITE_DEF("HOSTNAME", client); + WRITE_DEF("OSTYPE", ostype); + + pwent = getpwuid(geteuid()); + if (pwent && pwent->pw_name) + WRITE_DEF("USER", pwent->pw_name); + else + WRITE_DEF("USER", ""); - fprintf(tmpf, "#include \"%s\"\n", config_file); + { + const char *home = getenv("HOME"); + WRITE_DEF("HOME", (home != NULL) ? home : ""); + } - pclose(tmpf); - return(tmp_name); -} + WRITE_NUM("VERSION", ProtocolVersion(display)); + WRITE_NUM("REVISION", ProtocolRevision(display)); + WRITE_DEF("VENDOR", ServerVendor(display)); + WRITE_NUM("RELEASE", VendorRelease(display)); + + screen = ScreenOfDisplay(display, Mscreen); + visual = DefaultVisualOfScreen(screen); + WRITE_NUM("WIDTH", DisplayWidth(display, Mscreen)); + WRITE_NUM("HEIGHT", DisplayHeight(display, Mscreen)); + WRITE_NUM("X_RESOLUTION", Resolution(screen->width, screen->mwidth)); + WRITE_NUM("Y_RESOLUTION", Resolution(screen->height, screen->mheight)); + WRITE_NUM("PLANES", DisplayPlanes(display, Mscreen)); + WRITE_NUM("BITS_PER_RGB", visual->bits_per_rgb); + WRITE_NUM("SCREEN", Mscreen); + + switch (visual->class) { + case StaticGray: + vc = "StaticGray"; + break; + case GrayScale: + vc = "GrayScale"; + break; + case StaticColor: + vc = "StaticColor"; + break; + case PseudoColor: + vc = "PseudoColor"; + break; + case TrueColor: + vc = "TrueColor"; + break; + case DirectColor: + vc = "DirectColor"; + break; + default: + vc = "NonStandard"; + break; + } + + WRITE_DEF("CLASS", vc); + if (visual->class != StaticGray && visual->class != GrayScale) + WRITE_DEF("COLOR", "Yes"); + else + WRITE_DEF("COLOR", "No"); + WRITE_DEF("FVWM_VERSION", VERSION); + + feature_opts[0] = '\0'; +#ifdef SHAPE + strlcat(feature_opts, "SHAPE ", sizeof(feature_opts)); +#endif +#ifdef XPM + strlcat(feature_opts, "XPM ", sizeof(feature_opts)); +#endif + strlcat(feature_opts, "Cpp ", sizeof(feature_opts)); +#ifdef NO_SAVEUNDERS + strlcat(feature_opts, "NO_SAVEUNDERS ", sizeof(feature_opts)); +#endif + WRITE_DEF("OPTIONS", feature_opts); + WRITE_DEF("FVWM_MODULEDIR", FVWM_MODULEDIR); + WRITE_DEF("FVWM_CONFIGDIR", FVWM_CONFIGDIR); + + fprintf(cpp_in, "#include \"%s\"\n", config_file); + fflush(cpp_in); + fclose(cpp_in); + +#undef WRITE_DEF +#undef WRITE_NUM + + linebuf = xmalloc(line_cap); + while ((nread = fread(chunk, 1, sizeof(chunk), cpp_out)) > 0) { + if (mirror) + fwrite(chunk, 1, nread, mirror); + for (size_t i = 0; i < nread; i++) { + if (line_len + 1 >= line_cap) { + line_cap *= 2; + linebuf = xrealloc(linebuf, line_cap); + } + linebuf[line_len++] = chunk[i]; + if (chunk[i] == '\n') { + if (line_len >= 2 && + linebuf[line_len - 2] == '\\') { + /* Preserve fvwm's "\" line continuation + * semantics. */ + line_len -= 2; + continue; + } + linebuf[line_len] = '\0'; + if (!is_cpp_linemarker(linebuf)) + SendInfo(fd, linebuf, 0); + line_len = 0; + } + } + } + + if (ferror(cpp_out)) + perror("cpp output read"); + + if (line_len > 0) { + if (line_len + 2 >= line_cap) { + line_cap *= 2; + linebuf = xrealloc(linebuf, line_cap); + } + if (linebuf[line_len - 1] != '\n') { + linebuf[line_len++] = '\n'; + appended_newline = 1; + } + linebuf[line_len] = '\0'; + if (mirror && appended_newline) + fputc('\n', mirror); + if (!is_cpp_linemarker(linebuf)) + SendInfo(fd, linebuf, 0); + } + free(linebuf); + fclose(cpp_out); + if (mirror) + fclose(mirror); + if (waitpid(pid, &status, 0) == -1) { + perror("waitpid for cpp"); + status = 1; + } + + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + fprintf(stderr, "%s: cpp exited with status %d\n", MyName, + WEXITSTATUS(status)); + return -1; + } + + if (created_temp && kept_path[0] != '\0') { + char msg[BUFSIZ]; + snprintf(msg, sizeof(msg), + "Echo %s: preprocessor output kept in %s\n", MyName, + kept_path); + SendInfo(fd, msg, 0); + } + return 0; +} + +static int +is_cpp_linemarker(const char *line) +{ + const unsigned char *p; + + if (line == NULL) + return 0; + + p = (const unsigned char *)line; + while (*p == ' ' || *p == '\t') + p++; + if (*p != '#') + return 0; + p++; + while (*p == ' ' || *p == '\t') + p++; + if (*p == '\0' || *p == '\n') + return 1; + if (isdigit(*p)) { + while (isdigit(*p)) + p++; + while (*p == ' ' || *p == '\t') + p++; + if (*p == '\0' || *p == '\n' || *p == '"') + return 1; + } + if (strncmp((const char *)p, "line", 4) == 0) + return 1; + return 0; +} /*********************************************************************** * @@ -365,31 +505,34 @@ static char *cpp_defs(Display *display, const char *host, char *cpp_options, cha * SIGPIPE handler - SIGPIPE means fvwm is dying * ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(0); + exit(0); } -static char *MkDef(char *name, char *def) +static char * +MkDef(const char *name, const char *def) { - char *cp = NULL; - int n; + char *cp = NULL; + int n; - /* Get space to hold everything, if needed */ + /* Get space to hold everything, if needed */ - n = EXTRA + strlen(name) + strlen(def); - cp = safemalloc(n); + n = EXTRA + strlen(name) + strlen(def); + cp = xmalloc(n); - sprintf(cp, "#define %s %s\n",name,def); + snprintf(cp, n, "#define %s %s\n", name, def); - return(cp); + return (cp); } -static char *MkNum(char *name,int def) +static char * +MkNum(const char *name, int def) { - char num[20]; + char num[20]; - sprintf(num, "%d", def); + snprintf(num, sizeof(num), "%d", def); - return(MkDef(name, num)); + return (MkDef(name, num)); } Index: fvwm/modules/FvwmCpp/FvwmCpp.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmCpp/FvwmCpp.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmCpp/FvwmCpp.h --- fvwm/modules/FvwmCpp/FvwmCpp.h +++ fvwm/modules/FvwmCpp/FvwmCpp.h @@ -1,13 +1,9 @@ -#include "../../libs/fvwmlib.h" +#include "../../libs/fvwmlib.h" /************************************************************************* * * Subroutine Prototypes - * + * *************************************************************************/ void DeadPipe(int nonsense); - - - - Index: fvwm/modules/FvwmForm/FvwmForm.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmForm/FvwmForm.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmForm/FvwmForm.1 --- fvwm/modules/FvwmForm/FvwmForm.1 +++ fvwm/modules/FvwmForm/FvwmForm.1 @@ -1,29 +1,29 @@ .\" $OpenBSD: FvwmForm.1,v 1.2 2010/03/20 20:13:27 schwarze Exp $ -.TH FvwmForm 1 +.TH FVWMFORM 1 "February 1, 1995" "1.0" "FVWM Modules" .SH NAME -FvwmForm - input form module for Fvwm +FvwmForm \- input form module for Fvwm .SH SYNOPSIS -FvwmForm must be spawned by Fvwm. +FvwmForm must be spawned by Fvwm. It will not work from the command line. .SH DESCRIPTION FvwmForm provides a mechanism to get user input and act accordingly. This is achieved by means of a form that the user can fill out, and from which the user can select actions he wants Fvwm to take. A form consists of five types of items: -text labels, +text labels, single-line text inputs, mutually-exclusive selections, multiple-choice selections, and action buttons. These items are arranged into several lines, with a very flexible layout. - +.PP A text label only serves the purpose of explanation. It cannot accept any input. A text input field can be used to edit a single-line string. FvwmForm accepts Emacs-style cursor movement keys. No copying and pasting functions exist. - +.PP A selection consists of several choices. The selection itself is a logical entity that doesn't have any display feature. @@ -31,7 +31,7 @@ Each choice is displayed as a push-button followed by a explanatory text label. When selected, an exclusive choice shows a circle in the middle, while a multiple choice shows a check. - +.PP An action button, when clicked on, will send a set of commands to Fvwm. FvwmForm will do variable substitutions in the command text to reflect @@ -45,17 +45,17 @@ and they will be treated as different modules. Or, you can invoke FvwmForm with an optional parameter, which it will use as the name instead (e.g. 'Module FvwmForm QuitVerify'). That way you don't even have to make a symbolic link for it! - +.PP Be sure to set ModulePath in your .fvwmrc file to include FvwmForm's path. - +.PP When FvwmForm is invoked with a window context, e.g. from a window menu, all commands it sends to Fvwm will have that window context. .SH CONFIGURATION The following options can be set in the .fvwmrc file. Note that the string "FvwmForm" should be changed if another module with different name is used. - +.PP The order of the options DOES matter. In general, colors and fonts should be specified first. Lines, text labels, and input items should appear in their logical order. @@ -72,7 +72,6 @@ It saves the user some mouse-travelling. Puts the FvwmForm window at location (\fIx\fP, \fIy\fP) on the screen. By convention, a negative \fIx\fP (resp. \fIy\fP) value measures distance from the right (resp. bottom) of the screen. - If this option is omitted, FvwmForm will start at the center of the screen. .TP 4 .B *FvwmFormBack \fIcolor\fP @@ -104,7 +103,7 @@ A line can contain an arbitrary number of items whose options should follow. A FvwmForm window can have an arbitrary number of lines. The width of the window is that of the longest line. - +.PP Justification of items in the line is specified by \fIjustification\fP, which can be one of the following: .TP 16 @@ -151,7 +150,7 @@ Specifies a choice for a selection. The choice item has a \fIname\fP and a \fIvalue\fP. The \fIstring\fP will be displayed to the right of the choice button as a label. - +.PP The choice will assume the specified initial state ("on" means selected) when FvwmForm starts or resets. Note that if the selections are mutually exclusive, @@ -162,10 +161,10 @@ FvwmForm will assure only one is selected. .TP 4 .B *FvwmFormButton \fItype\fP "\fIstring\fP" [\fIkey\fP] This option specifies an action button. -The button has \fIstring\fP as a label, +The button has \fIstring\fP as a label, and excutes a set of Fvwm \fIcommand\fP when it is activated. The commands should be specified using the *FvwmFormCommand option. - +.PP The optional \fIkey\fP specifies a keyboard shortcut that activates the button. It is in either a control character, specified as ^@, ^A, ..., ^_, @@ -173,14 +172,14 @@ or a function key, specified as F1, F2, ..., F35. Control keys that are used for cursor movement in text input fields cannot activate any buttons, with the exception of TAB, RETURN, LINEFEED, which can activate a button when the cursor is in the last text input field. - +.PP The behavior of the button is determined by \fItype\fP: .TP 16 continue FvwmForm will resume execution after sending the commands. .TP 16 restart -After sending the commands, +After sending the commands, FvwmForm will reset all the values to the initial ones, and then resume execution. .TP 16 @@ -191,7 +190,7 @@ FvwmForm will quit after sending the commands. This option specifies an Fvwm command associated with the current button. Commands that appear before any *FvwmFormButton option will be executed at start-up time. This is usually a beep that gets the user's attention. - +.PP Before sending each command to Fvwm, FvwmForm recognizes variables of the following forms, and supply values to them. .TP 16 @@ -199,12 +198,12 @@ following forms, and supply values to them. If \fIname\fP corresponds to a text input field, the result is the user's input string. Special chars such as ", ', and \ will be preceded by a backslash. - +.PP If \fIname\fP corresponds to a choice, the result is the value of the choice (as specified in *FvwmFormChoice) if the choice is selected. If the choice is not selected, the result is a blank string. - +.PP If \fIname\fP corresponds to a selection, the result will be a list of the selected values of all its choices. .TP 16 @@ -213,7 +212,7 @@ If \fIname\fP is a text input field and its value is not an empty string, the result is \fIstring\fP, with recursive variable substitution applied. If the input value is empty, the result is empty. - +.PP If \fIname\fP is a choice and it is selected, the result is \fIstring\fP, with recursive variable substitution applied. @@ -223,170 +222,101 @@ If the choice is not selected, the result is empty. The same as the above, except that the converse conditions are taken. .SH EXAMPLE 1 - QuitVerify This example simulates the mwm way of confirming logout. - +.RS +.nf *QuitVerifyGrabServer -.br *QuitVerifyWarpPointer -.br -*QuitVerifyFont *helvetica*m*r*n*14* -.br -*QuitVerifyButtonFont *helvetica*m*o*n*14* -.br -*QuitVerifyFore Black -.br -*QuitVerifyBack Light Gray -.br -*QuitVerifyItemFore Wheat -.br -*QuitVerifyItemBack Gray50 -.br +*QuitVerifyFont *helvetica*m*r*n*14* +*QuitVerifyButtonFont *helvetica*m*o*n*14* +*QuitVerifyFore Black +*QuitVerifyBack Light Gray +*QuitVerifyItemFore Wheat +*QuitVerifyItemBack Gray50 # begin items -.br -*QuitVerifyCommand Beep -.br -*QuitVerifyLine center -.br -*QuitVerifyText "Do you really want to logout?" -.br -*QuitVerifyLine expand -.br -*QuitVerifyButton quit "Logout" ^M -.br -*QuitVerifyCommand Quit -.br -*QuitVerifyButton quit "Cancel" ^[ -.br -*QuitVerifyCommand Nop -.br +*QuitVerifyCommand Beep +*QuitVerifyLine center +*QuitVerifyText "Do you really want to logout?" +*QuitVerifyLine expand +*QuitVerifyButton quit "Logout" ^M +*QuitVerifyCommand Quit +*QuitVerifyButton quit "Cancel" ^[ +*QuitVerifyCommand Nop # Fvwm window style -.br Style "QuitVerify" NoTitle, NoHandles, BorderWidth 3 - +.fi +.RE .SH EXAMPLE 2 - Remote Login -This example lets the user type in a hostname, +This example lets the user type in a hostname, and optionally a user name on the remote machine, and opens an xterm window from the remote host. - +.RS +.nf *RloginWarpPointer -.br -*RloginFont *helvetica*m*r*n*14* -.br -*RloginButtonFont *helvetica*m*o*n*14* -.br -*RloginInputFont *cour*m*r*n*14* -.br -*RloginFore Black -.br -*RloginBack Light Gray -.br -*RloginItemFore Wheat -.br -*RloginItemBack Gray50 -.br +*RloginFont *helvetica*m*r*n*14* +*RloginButtonFont *helvetica*m*o*n*14* +*RloginInputFont *cour*m*r*n*14* +*RloginFore Black +*RloginBack Light Gray +*RloginItemFore Wheat +*RloginItemBack Gray50 # begin items -.br -*RloginLine center -.br -*RloginText "Login to Remote Host" -.br -*RloginLine center -.br -*RloginText "Host:" -.br -*RloginInput HostName 20 "" -.br -*RloginLine center -.br -*RloginSelection UserSel single -.br -*RloginChoice Default Default on "same user" -.br -*RloginChoice Custom Custom off "user:" -.br -*RloginInput UserName 10 "" -.br -*RloginLine expand -.br -*RloginButton quit "Login" ^M -.br -*RloginCommand Exec exec rsh $(Custom?-l $(UserName)) $(HostName) xterm -T xterm@$(HostName) -display $HOSTDISPLAY & -.br -*RloginButton restart "Clear" -.br -*RloginButton quit "Cancel" ^[ -.br -*RloginCommand Nop - +*RloginLine center +*RloginText "Login to Remote Host" +*RloginLine center +*RloginText "Host:" +*RloginInput HostName 20 "" +*RloginLine center +*RloginSelection UserSel single +*RloginChoice Default Default on "same user" +*RloginChoice Custom Custom off "user:" +*RloginInput UserName 10 "" +*RloginLine expand +*RloginButton quit "Login" ^M +*RloginCommand Exec exec rsh $(Custom?-l $(UserName)) $(HostName) \ +xterm -T xterm@$(HostName) -display $HOSTDISPLAY & +*RloginButton restart "Clear" +*RloginButton quit "Cancel" ^[ +*RloginCommand Nop +.fi +.RE .SH EXAMPLE 3 - Capture Window This example provides a front-end to xwd, xwud, and xpr. - -*CaptureFont *helvetica*m*r*n*14* -.br -*CaptureButtonFont *helvetica*m*o*n*14* -.br -*CaptureInputFont *cour*m*r*n*14* -.br -*CaptureLine center -.br -*CaptureText "Capture Window" -.br -*CaptureLine left -.br -*CaptureText "File: " -.br -*CaptureInput file 25 "/tmp/Capture" -.br -*CaptureLine left -.br -*CaptureText "Printer: " -.br -*CaptureInput printer 20 "ps1" -.br -*CaptureLine expand -.br -*CaptureSelection PtrType single -.br -*CaptureChoice PS ps on "PostScript" -.br -*CaptureChoice Ljet ljet off "HP LaserJet" -.br -*CaptureLine left -.br -*CaptureText "xwd options:" -.br -*CaptureLine expand -.br -*CaptureSelection Options multiple -.br -*CaptureChoice Brd -nobdrs off "No border" -.br -*CaptureChoice Frm -frame on "With frame" -.br -*CaptureChoice XYZ -xy off "XY format" -.br -*CaptureLine expand -.br -*CaptureButton continue "Capture" ^M -.br -*CaptureCommand Exec exec xwd -out $(file) $(Options) & -.br -*CaptureButton continue "Preview" -.br -*CaptureCommand Exec exec xwud -in $(file) & -.br -*CaptureButton continue "Print" -.br -*CaptureCommand Exec xpr -device $(PtrType) $(file) | lpr -P $(printer) & -.br -*CaptureButton quit "Quit" - -.SH BUGS AND LIMITATIONS -There is a hard-coded limit on the number of items. - -Report bugs to ztfeng@math.princeton.edu. +.RS +.nf +*CaptureFont *helvetica*m*r*n*14* +*CaptureButtonFont *helvetica*m*o*n*14* +*CaptureInputFont *cour*m*r*n*14* +*CaptureLine center +*CaptureText "Capture Window" +*CaptureLine left +*CaptureText "File: " +*CaptureInput file 25 "/tmp/Capture" +*CaptureLine left +*CaptureText "Printer: " +*CaptureInput printer 20 "ps1" +*CaptureLine expand +*CaptureSelection PtrType single +*CaptureChoice PS ps on "PostScript" +*CaptureChoice Ljet ljet off "HP LaserJet" +*CaptureLine left +*CaptureText "xwd options:" +*CaptureLine expand +*CaptureSelection Options multiple +*CaptureChoice Brd -nobdrs off "No border" +*CaptureChoice Frm -frame on "With frame" +*CaptureChoice XYZ -xy off "XY format" +*CaptureLine expand +*CaptureButton continue "Capture" ^M +*CaptureCommand Exec exec xwd -out $(file) $(Options) & +*CaptureButton continue "Preview" +*CaptureCommand Exec exec xwud -in $(file) & +*CaptureButton continue "Print" +*CaptureCommand Exec xpr -device $(PtrType) $(file) | lpr -P $(printer) & +*CaptureButton quit "Quit" +.fi +.RE .SH COPYRIGHT FvwmForm is original work of Thomas Zuwei Feng. - Copyright Feb 1995, Thomas Zuwei Feng. No guarantees or warantees are provided or implied in any way whatsoever. Use this program at your own risk. Permission to use, modify, and redistribute this program is hereby Index: fvwm/modules/FvwmForm/FvwmForm.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmForm/FvwmForm.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmForm/FvwmForm.c --- fvwm/modules/FvwmForm/FvwmForm.c +++ fvwm/modules/FvwmForm/FvwmForm.c @@ -5,29 +5,33 @@ * risk. Permission to use, modify, and redistribute this program is hereby * given, provided that this copyright is kept intact. */ -#include "config.h" - -#include "../../libs/fvwmlib.h" +#include +#include -#include #include - -#include -#include #include +#include +#include +#include + +#include "../../libs/fvwmlib.h" +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" #if HAVE_SYS_SELECT_H #include #endif -#include #include +#include #include #include #define XK_MISCELLANY #include -void dummy (FILE *f, const char *fmt, ...) { +void +dummy(FILE *f, const char *fmt, ...) +{ } #ifdef DEBUG @@ -36,110 +40,107 @@ void dummy (FILE *f, const char *fmt, ...) { #define fprintf dummy #endif +#define TEXT_SPC 3 +#define BOX_SPC 3 +#define ITEM_HSPC 10 +#define ITEM_VSPC 5 -#define TEXT_SPC 3 -#define BOX_SPC 3 -#define ITEM_HSPC 10 -#define ITEM_VSPC 5 - -/* tba: use dynamic buffer expanding */ -#define MAX_LINES 50 -#define MAX_ITEMS 100 -#define ITEMS_PER_LINE 64 -#define CHOICES_PER_SEL 64 +/* initial allocation sizes, structures grow dynamically as needed */ +#define INITIAL_LINE_CAPACITY 8 +#define INITIAL_LINE_ITEMS_CAPACITY 8 +#define INITIAL_ITEMS_CAPACITY 128 +#define INITIAL_CHOICES_CAPACITY 8 -#define I_TEXT 1 -#define I_INPUT 2 -#define I_SELECT 3 -#define I_CHOICE 4 -#define I_BUTTON 5 +#define I_TEXT 1 +#define I_INPUT 2 +#define I_SELECT 3 +#define I_CHOICE 4 +#define I_BUTTON 5 -#define IS_SINGLE 1 -#define IS_MULTIPLE 2 +#define IS_SINGLE 1 +#define IS_MULTIPLE 2 -#define IB_CONTINUE 1 -#define IB_RESTART 2 -#define IB_QUIT 3 +#define IB_CONTINUE 1 +#define IB_RESTART 2 +#define IB_QUIT 3 typedef union _item { - int type; /* item type, one of I_TEXT .. I_BUTTON */ - struct _head { /* common header */ - int type; - int win; /* X window id */ - char *name; /* identifier name */ - int size_x, size_y; /* size of bounding box */ - int pos_x, pos_y; /* position of top-left corner */ - } header; - struct { /* I_TEXT */ - struct _head head; - int n; /* string length */ - char *value; /* string to display */ - } text; - struct { /* I_INPUT */ - struct _head head; - int buf; /* input string buffer */ - int n; /* string length */ - char *value; /* input string */ - char *init_value; /* default string */ - char *blanks; /* blank string */ - int size; /* input field size */ - int left; /* position of the left-most displayed char */ - int o_cursor; /* store relative cursor position */ - } input; - struct { /* I_SELECT */ - struct _head head; - int key; /* one of IS_MULTIPLE, IS_SINGLE */ - int n; /* number of choices */ - union _item **choices; /* list of choices */ - } select; - struct { /* I_CHOICE */ - struct _head head; - int on; /* selected or not */ - int init_on; /* initially selected or not */ - char *value; /* value if selected */ - int n; /* text string length */ - char *text; /* text string */ - union _item *sel; /* selection it belongs to */ - } choice; - struct { /* I_BUTTON */ - struct _head head; - int key; /* one of IB_CONTINUE, IB_RESTART, IB_QUIT */ - int n; /* # of commands */ - int len; /* text length */ - char *text; /* text string */ - int keypress; /* short cut */ - /* Fvwm command to execute */ - char **commands; - } button; + int type; /* item type, one of I_TEXT .. I_BUTTON */ + struct _head { /* common header */ + int type; + int win; /* X window id */ + char *name; /* identifier name */ + int size_x, size_y; /* size of bounding box */ + int pos_x, pos_y; /* position of top-left corner */ + } header; + struct { /* I_TEXT */ + struct _head head; + int n; /* string length */ + char *value; /* string to display */ + } text; + struct { /* I_INPUT */ + struct _head head; + int buf; /* input string buffer */ + int n; /* string length */ + char *value; /* input string */ + char *init_value; /* default string */ + char *blanks; /* blank string */ + int size; /* input field size */ + int left; /* position of the left-most displayed char */ + int o_cursor; /* store relative cursor position */ + } input; + struct { /* I_SELECT */ + struct _head head; + int key; /* one of IS_MULTIPLE, IS_SINGLE */ + int n; /* number of choices */ + union _item **choices; /* list of choices */ + int choices_cap; + } select; + struct { /* I_CHOICE */ + struct _head head; + int on; /* selected or not */ + int init_on; /* initially selected or not */ + char *value; /* value if selected */ + int n; /* text string length */ + char *text; /* text string */ + union _item *sel; /* selection it belongs to */ + } choice; + struct { /* I_BUTTON */ + struct _head head; + int key; /* one of IB_CONTINUE, IB_RESTART, IB_QUIT */ + int n; /* # of commands */ + int len; /* text length */ + char *text; /* text string */ + int keypress; /* short cut */ + /* Fvwm command to execute */ + char **commands; + int commands_cap; + } button; } Item; - -#define L_LEFT 1 -#define L_RIGHT 2 -#define L_CENTER 3 -#define L_LEFTRIGHT 4 +#define L_LEFT 1 +#define L_RIGHT 2 +#define L_CENTER 3 +#define L_LEFTRIGHT 4 typedef struct _line { - int n; /* number of items on the line */ - int justify; /* justification */ - int size_x, size_y; /* size of bounding rectangle */ - Item **items; /* list of items */ + int n; /* number of items on the line */ + int justify; /* justification */ + int size_x, size_y; /* size of bounding rectangle */ + Item **items; /* list of items */ + int items_cap; /* capacity of items array */ } Line; - -/* global variables */ -char *prog_name; /* program name, e.g. FvwmForm */ - -int fd_in; /* fd for Fvwm->Module packets */ -int fd_out; /* fd for Module->Fvwm packets */ -int fd[2]; /* pipe pair */ -int fd_err; +int fd_in; /* fd for Fvwm->Module packets */ +int fd_out; /* fd for Module->Fvwm packets */ FILE *fp_err; -Line lines[MAX_LINES]; +Line *lines = NULL; int n_lines; -Item items[MAX_ITEMS]; +int lines_capacity = 0; +Item *items = NULL; int n_items; +int items_capacity = 0; Item def_button; int grab_server = 0, server_grabbed = 0; @@ -147,27 +148,24 @@ int gx, gy, geom = 0; int warp_pointer = 0; Display *dpy; -int fd_x; /* fd for X connection */ +int fd_x; /* fd for X connection */ +char *prog_name; +int fd[2]; +int fd_err; Window root, frame, ref; Colormap d_cmap; int screen; int scr_depth; -int max_width, total_height; /* frame size */ +int max_width, total_height; /* frame size */ enum { c_back, c_fore, c_itemback, c_itemfore, c_itemlo, c_itemhi }; -char *color_names[4] = { - "Light Gray", "Black", "Gray50", "Wheat" -}; +char *color_names[4] = {"Light Gray", "Black", "Gray50", "Wheat"}; unsigned long colors[6]; enum { f_text, f_input, f_button }; -char *font_names[3] = { - "fixed", - "fixed", - "fixed" -}; +char *font_names[3] = {"fixed", "fixed", "fixed"}; Font fonts[3]; XFontStruct *xfs[3]; @@ -182,1396 +180,1793 @@ int rel_cursor; static char *buf; static int N = 8; +static void +ensure_line_capacity(int count) +{ + if (lines_capacity >= count) { + return; + } + int new_cap = lines_capacity ? lines_capacity : INITIAL_LINE_CAPACITY; + while (new_cap < count) { + new_cap *= 2; + } + lines = (Line *)realloc(lines, sizeof(Line) * new_cap); + for (int i = lines_capacity; i < new_cap; ++i) { + lines[i].n = 0; + lines[i].justify = L_CENTER; + lines[i].size_x = 0; + lines[i].size_y = 0; + lines[i].items = NULL; + lines[i].items_cap = 0; + } + lines_capacity = new_cap; +} + +static void +ensure_line_item_capacity(Line *line, int count) +{ + if (line->items_cap >= count) { + return; + } + int new_cap = + line->items_cap ? line->items_cap : INITIAL_LINE_ITEMS_CAPACITY; + while (new_cap < count) { + new_cap *= 2; + } + line->items = (Item **)realloc(line->items, sizeof(Item *) * new_cap); + line->items_cap = new_cap; +} + +static Line * +add_line(int justify) +{ + ensure_line_capacity(n_lines + 1); + Line *line = &lines[n_lines++]; + line->n = 0; + line->justify = justify; + line->size_x = 0; + line->size_y = 0; + if (!line->items) { + line->items_cap = 0; + } + ensure_line_item_capacity(line, 1); + return line; +} + +static void +append_item_to_line(Line *line, Item *item) +{ + ensure_line_item_capacity(line, line->n + 1); + line->items[line->n++] = item; + line->size_x += item->header.size_x; + if (line->size_y < item->header.size_y) { + line->size_y = item->header.size_y; + } +} + /* copy a string until '\0', or up to n chars, and delete trailing spaces */ -char *CopyNString (char *cp, int n) +char * +CopyNString(char *cp, int n) { - char *dp, *bp; - if (n == 0) - n = strlen(cp); - bp = dp = (char *)malloc(n+1); - while (n-- > 0) - *dp++ = *cp++; - while (isspace(*(--dp))); - *(++dp) = '\0'; - return bp; + char *dp, *bp; + if (n == 0) + n = strlen(cp); + bp = dp = (char *)malloc(n + 1); + while (n-- > 0) + *dp++ = *cp++; + while (isspace(*(--dp))) + ; + *(++dp) = '\0'; + return bp; } /* copy a string until '"', or '\n', or '\0' */ -char *CopyQuotedString (char *cp) +char * +CopyQuotedString(char *cp) { - char *dp, *bp, c; - bp = dp = (char *)malloc(strlen(cp) + 1); - while (1) { - switch (c = *(cp++)) { - case '\\': - *(dp++) = *(cp++); - break; - case '\"': - case '\n': - case '\0': - *dp = '\0'; - return bp; - break; - default: - *(dp++) = c; - break; - } - } + char *dp, *bp, c; + bp = dp = (char *)malloc(strlen(cp) + 1); + sandbox_x11_config("FvwmForm"); + + while (1) { + switch (c = *(cp++)) { + case '\\': + *(dp++) = *(cp++); + break; + case '\"': + case '\n': + case '\0': + *dp = '\0'; + return bp; + break; + default: + *(dp++) = c; + break; + } + } } /* copy a string until the first space */ -char *CopySolidString (char *cp) +char * +CopySolidString(char *cp) { - char *dp, *bp, c; - bp = dp = (char *)malloc(strlen(cp) + 1); - while (1) { - c = *(cp++); - if (c == '\\') { - *(dp++) = '\\'; - *(dp++) = *(cp++); - } else if (isspace(c) || c == '\0') { - *dp = '\0'; - return bp; - } else - *(dp++) = c; - } + char *dp, *bp, c; + bp = dp = (char *)malloc(strlen(cp) + 1); + while (1) { + c = *(cp++); + if (c == '\\') { + *(dp++) = '\\'; + *(dp++) = *(cp++); + } else if (isspace(c) || c == '\0') { + *dp = '\0'; + return bp; + } else + *(dp++) = c; + } } /* get the font height */ -int FontHeight (XFontStruct *xfs) +int +FontHeight(XFontStruct *xfs) { - return (xfs->ascent + xfs->descent); + return (xfs->ascent + xfs->descent); } /* get the font width, for fixed-width font only */ -int FontWidth (XFontStruct *xfs) +int +FontWidth(XFontStruct *xfs) { - return (xfs->per_char[0].width); + return (xfs->per_char[0].width); } /* read the configuration file */ -void ReadConfig () +void +ReadConfig() { - FILE *fopen(); - int prog_name_len, i, j, l, extra; - char *line_buf; - char *cp; - Line *cur_line, *line; - Item *item, *cur_sel, *cur_button; - -#define AddToLine(item) { cur_line->items[cur_line->n++] = item; cur_line->size_x += item->header.size_x; if (cur_line->size_y < item->header.size_y) cur_line->size_y = item->header.size_y; } - - n_items = 0; - n_lines = 0; - - /* default line in case the first *FFLine is missing */ - lines[0].n = 0; - lines[0].justify = L_CENTER; - lines[0].size_x = lines[0].size_y = 0; - lines[0].items = (Item **)malloc(sizeof(Item *) * ITEMS_PER_LINE); - cur_line = lines; - - /* default button is for initial functions */ - cur_button = &def_button; - def_button.button.n = 0; - def_button.button.commands = (char **)malloc(sizeof(char *) * MAX_ITEMS); - def_button.button.key = IB_CONTINUE; - - /* default fonts in case the *FFFont's are missing */ - xfs[f_text] = xfs[f_input] = xfs[f_button] = - GetFontOrFixed(dpy, "fixed"); - fonts[f_text] = fonts[f_input] = fonts[f_button] = xfs[f_text]->fid; - - prog_name_len = strlen(prog_name); - - while (GetConfigLine(fd,&line_buf),line_buf) { - cp = line_buf; - while (isspace(*cp)) cp++; /* skip blanks */ - if (*cp != '*') continue; - if (strncmp(++cp, prog_name, prog_name_len) != 0) continue; - cp += prog_name_len; - /* at this point we have recognized "*FvwmForm" */ - if (strncmp(cp, "GrabServer", 10) == 0) { - grab_server = 1; - continue; - } - else if (strncmp(cp, "WarpPointer", 11) == 0) { - warp_pointer = 1; - } - else if (strncmp(cp, "Position", 8) == 0) { - cp += 8; - geom = 1; - while (isspace(*cp)) cp++; - gx = atoi(cp); - while (!isspace(*cp)) cp++; - while (isspace(*cp)) cp++; - gy = atoi(cp); - fprintf(fp_err, "Position @ (%d, %d)\n", gx, gy); - continue; - } - else if (strncmp(cp, "Fore", 4) == 0) { - cp += 4; - while (isspace(*cp)) cp++; - color_names[c_fore] = CopyNString(cp, 0); - fprintf(fp_err, "ColorFore: %s\n", color_names[c_fore]); - continue; - } else if (strncmp(cp, "Back", 4) == 0) { - cp += 4; - while (isspace(*cp)) cp++; - color_names[c_back] = CopyNString(cp, 0); - fprintf(fp_err, "ColorBack: %s\n", color_names[c_back]); - continue; - } else if (strncmp(cp, "ItemFore", 8) == 0) { - cp += 8; - while (isspace(*cp)) cp++; - color_names[c_itemfore] = CopyNString(cp, 0); - fprintf(fp_err, "ColorItemFore: %s\n", color_names[c_itemfore]); - continue; - } else if (strncmp(cp, "ItemBack", 8) == 0) { - cp += 8; - while (isspace(*cp)) cp++; - color_names[c_itemback] = CopyNString(cp, 0); - fprintf(fp_err, "ColorItemBack: %s\n", color_names[c_itemback]); - continue; - } else if (strncmp(cp, "Font", 4) == 0) { - cp += 4; - while (isspace(*cp)) cp++; - font_names[f_text] = CopyNString(cp, 0); - fprintf(fp_err, "Font: %s\n", font_names[f_text]); - xfs[f_text] = GetFontOrFixed(dpy, font_names[f_text]); - fonts[f_text] = xfs[f_text]->fid; - continue; - } else if (strncmp(cp, "ButtonFont", 10) == 0) { - cp += 10; - while (isspace(*cp)) cp++; - font_names[f_button] = CopyNString(cp, 0); - fprintf(fp_err, "ButtonFont: %s\n", font_names[f_button]); - xfs[f_button] = GetFontOrFixed(dpy, font_names[f_button]); - fonts[f_button] = xfs[f_button]->fid; - continue; - } else if (strncmp(cp, "InputFont", 9) == 0) { - cp += 9; - while (isspace(*cp)) cp++; - font_names[f_input] = CopyNString(cp, 0); - fprintf(fp_err, "InputFont: %s\n", font_names[f_input]); - xfs[f_input] = GetFontOrFixed(dpy, font_names[f_input]); - fonts[f_input] = xfs[f_input]->fid; - continue; - } else if (strncmp(cp, "Line", 4) == 0) { - cp += 4; - cur_line = lines + n_lines++; - while (isspace(*cp)) cp++; - if (strncmp(cp, "left", 4) == 0) - cur_line->justify = L_LEFT; - else if (strncmp(cp, "right", 5) == 0) - cur_line->justify = L_RIGHT; - else if (strncmp(cp, "center", 6) == 0) - cur_line->justify = L_CENTER; - else - cur_line->justify = L_LEFTRIGHT; - cur_line->n = 0; - cur_line->items = (Item **)malloc(sizeof(Item *) * ITEMS_PER_LINE); - continue; - } else if (strncmp(cp, "Text", 4) == 0) { -/* syntax: *FFText "" */ - cp += 4; - item = items + n_items++; - item->type = I_TEXT; - item->header.name = ""; - while (isspace(*cp)) cp++; - if (*cp == '\"') - item->text.value = CopyQuotedString(++cp); - else - item->text.value = ""; - item->text.n = strlen(item->text.value); - item->header.size_x = XTextWidth(xfs[f_text], item->text.value, - item->text.n) + 2 * TEXT_SPC; - item->header.size_y = FontHeight(xfs[f_text]) + 2 * TEXT_SPC; - fprintf(fp_err, "Text \"%s\" [%d, %d]\n", item->text.value, - item->header.size_x, item->header.size_y); - AddToLine(item); - continue; - } - else if (strncmp(cp, "Input", 5) == 0) { -/* syntax: *FFInput "" */ - cp += 5; - item = items + n_items++; - item->type = I_INPUT; - while (isspace(*cp)) cp++; - item->header.name = CopySolidString(cp); - cp += strlen(item->header.name); - while (isspace(*cp)) cp++; - item->input.size = atoi(cp); - while (!isspace(*cp)) cp++; - while (isspace(*cp)) cp++; - if (*cp == '\"') - item->input.init_value = CopyQuotedString(++cp); - else - item->input.init_value = ""; - item->input.blanks = (char *)malloc(item->input.size); - for (j = 0; j < item->input.size; j++) - item->input.blanks[j] = ' '; - item->input.buf = strlen(item->input.init_value) + 1; - item->input.value = (char *)malloc(item->input.buf); - item->header.size_x = FontWidth(xfs[f_input]) * item->input.size - + 2 * TEXT_SPC + 2 * BOX_SPC; - item->header.size_y = FontHeight(xfs[f_input]) + 3 * TEXT_SPC - + 2 * BOX_SPC; - fprintf(fp_err, "Input, %s, [%d], \"%s\"\n", item->header.name, - item->input.size, item->input.init_value); - AddToLine(item); - } - else if (strncmp(cp, "Selection", 9) == 0) { -/* syntax: *FFSelection single | multiple */ - cp += 9; - cur_sel = items + n_items++; - cur_sel->type = I_SELECT; - while (isspace(*cp)) cp++; - cur_sel->header.name = CopySolidString(cp); - cp += strlen(cur_sel->header.name); - while (isspace(*cp)) cp++; - if (strncmp(cp, "multiple", 8) == 0) - cur_sel->select.key = IS_MULTIPLE; - else - cur_sel->select.key = IS_SINGLE; - cur_sel->select.n = 0; - cur_sel->select.choices = - (Item **)malloc(sizeof(Item *) * CHOICES_PER_SEL); - continue; - } else if (strncmp(cp, "Choice", 6) == 0) { -/* syntax: *FFChoice [on | _off_] [""] */ - cp += 6; - item = items + n_items++; - item->type = I_CHOICE; - while (isspace(*cp)) cp++; - item->header.name = CopySolidString(cp); - cp += strlen(item->header.name); - while (isspace(*cp)) cp++; - item->choice.value = CopySolidString(cp); - cp += strlen(item->choice.value); - while (isspace(*cp)) cp++; - if (strncmp(cp, "on", 2) == 0) - item->choice.init_on = 1; - else - item->choice.init_on = 0; - while (!isspace(*cp)) cp++; - while (isspace(*cp)) cp++; - if (*cp == '\"') - item->choice.text = CopyQuotedString(++cp); - else - item->choice.text = ""; - item->choice.n = strlen(item->choice.text); - item->choice.sel = cur_sel; - cur_sel->select.choices[cur_sel->select.n++] = item; - item->header.size_y = FontHeight(xfs[f_text]) + 2 * TEXT_SPC; - item->header.size_x = FontHeight(xfs[f_text]) + 4 * TEXT_SPC + - XTextWidth(xfs[f_text], item->choice.text, item->choice.n); - fprintf(fp_err, "Choice %s, \"%s\", [%d, %d]\n", item->header.name, - item->choice.text, item->header.size_x, item->header.size_y); - AddToLine(item); - continue; - } else if (strncmp(cp, "Button", 6) == 0) { -/* syntax: *FFButton continue | restart | quit "" */ - cp += 6; - item = items + n_items++; - item->type = I_BUTTON; - item->header.name = ""; - while (isspace(*cp)) cp++; - if (strncmp(cp, "restart", 7) == 0) - item->button.key = IB_RESTART; - else if (strncmp(cp, "quit", 4) == 0) - item->button.key = IB_QUIT; - else - item->button.key = IB_CONTINUE; - while (!isspace(*cp)) cp++; - while (isspace(*cp)) cp++; - if (*cp == '\"') { - item->button.text = CopyQuotedString(++cp); - cp += strlen(item->button.text) + 1; - while (isspace(*cp)) cp++; - } else - item->button.text = ""; - if (*cp == '^') - item->button.keypress = *(++cp) - '@'; - else if (*cp == 'F') - item->button.keypress = 256 + atoi(++cp); - else - item->button.keypress = -1; - item->button.len = strlen(item->button.text); - item->button.n = 0; - item->button.commands = (char **)malloc(sizeof(char *) * MAX_ITEMS); - item->header.size_y = FontHeight(xfs[f_button]) + 2 * TEXT_SPC - + 2 * BOX_SPC; - item->header.size_x = 2 * TEXT_SPC + 2 * BOX_SPC - + XTextWidth(xfs[f_button], item->button.text, item->button.len); - AddToLine(item); - cur_button = item; - continue; - } else if (strncmp(cp, "Command", 7) == 0) { -/* syntax: *FFCommand */ - cp += 7; - while (isspace(*cp)) cp++; - cur_button->button.commands[cur_button->button.n++] = - CopyNString(cp, 0); - } - } /* end of switch() */ - /* get the geometry right */ - max_width = 0; - total_height = ITEM_VSPC; - for (l = 0; l < n_lines; l++) { - line = lines + l; - for (i = 0; i < line->n; i++) { - line->items[i]->header.pos_y = total_height; - if (line->items[i]->header.size_y < line->size_y) - line->items[i]->header.pos_y += (line->size_y - line->items[i]->header.size_y) / 2 + 1 ; - } - total_height += ITEM_VSPC + line->size_y; - line->size_x += (line->n + 1) * ITEM_HSPC; - if (line->size_x > max_width) - max_width = line->size_x; - } - for (l = 0; l < n_lines; l++) { - int width; - line = lines + l; - fprintf(fp_err, "Line[%d], %d, %d items\n", l, line->justify, line->n); - switch (line->justify) { - case L_LEFT: - width = ITEM_HSPC; - for (i = 0; i < line->n; i++) { - line->items[i]->header.pos_x = width; - width += ITEM_HSPC + line->items[i]->header.size_x; - } - break; - case L_RIGHT: - width = max_width - line->size_x + ITEM_HSPC; - for (i = 0; i < line->n; i++) { - line->items[i]->header.pos_x = width; - width += ITEM_HSPC + line->items[i]->header.size_x; - } - break; - case L_CENTER: - width = (max_width - line->size_x) / 2 + ITEM_HSPC; - for (i = 0; i < line->n; i++) { - line->items[i]->header.pos_x = width; - fprintf(fp_err, "Line[%d], Item[%d] @ (%d, %d)\n", l, i, - line->items[i]->header.pos_x, line->items[i]->header.pos_y); - width += ITEM_HSPC + line->items[i]->header.size_x; - } - break; - case L_LEFTRIGHT: - /* count the number of inputs on the line - the extra space will be - * shared amongst these if there are any, otherwise it will be added - * as space in between the elements - */ - extra = 0 ; - for (i = 0 ; i < line->n ; i++) { - if (line->items[i]->type == I_INPUT) - extra++ ; - } - if (extra == 0) { - if (line->n < 2) { /* same as L_CENTER */ - width = (max_width - line->size_x) / 2 + ITEM_HSPC; - for (i = 0; i < line->n; i++) { - line->items[i]->header.pos_x = width; - width += ITEM_HSPC + line->items[i]->header.size_x; - } - } else { - extra = (max_width - line->size_x) / (line->n - 1); - width = ITEM_HSPC; - for (i = 0; i < line->n; i++) { - line->items[i]->header.pos_x = width; - width += ITEM_HSPC + line->items[i]->header.size_x + extra; - } - } - } else { - extra = (max_width - line->size_x) / extra ; - width = ITEM_HSPC ; - for (i = 0 ; i < line->n ; i++) { - line->items[i]->header.pos_x = width ; - if (line->items[i]->type == I_INPUT) - line->items[i]->header.size_x += extra ; - width += ITEM_HSPC + line->items[i]->header.size_x ; - } - } - break; - } - } + int prog_name_len, i, j, l, extra; + char *line_buf; + char *cp; + Line *cur_line, *line; + Item *item, *cur_sel, *cur_button; + + /* ensure items array capacity (dynamic) */ + if (!items) { + items_capacity = INITIAL_ITEMS_CAPACITY; + items = (Item *)malloc(sizeof(Item) * items_capacity); + } + + n_items = 0; + + /* default line in case the first *FFLine is missing */ + ensure_line_capacity(1); + n_lines = 0; + cur_line = add_line(L_CENTER); + + /* default button is for initial functions */ + cur_button = &def_button; + def_button.button.n = 0; + if (!def_button.button.commands) { + def_button.button.commands = + (char **)malloc(sizeof(char *) * 8); + def_button.button.commands_cap = 8; + } + def_button.button.key = IB_CONTINUE; + cur_sel = NULL; + + /* default fonts in case the *FFFont's are missing */ + xfs[f_text] = xfs[f_input] = xfs[f_button] = + GetFontOrFixed(dpy, "fixed"); + fonts[f_text] = fonts[f_input] = fonts[f_button] = xfs[f_text]->fid; + + prog_name_len = strlen(prog_name); + + while (GetConfigLine(fd, &line_buf), line_buf) { + cp = line_buf; + while (isspace(*cp)) + cp++; /* skip blanks */ + if (*cp != '*') + continue; + if (strncmp(++cp, prog_name, prog_name_len) != 0) + continue; + cp += prog_name_len; + /* at this point we have recognized "*FvwmForm" */ + if (strncmp(cp, "GrabServer", 10) == 0) { + grab_server = 1; + continue; + } else if (strncmp(cp, "WarpPointer", 11) == 0) { + warp_pointer = 1; + } else if (strncmp(cp, "Position", 8) == 0) { + cp += 8; + geom = 1; + while (isspace(*cp)) + cp++; + gx = atoi(cp); + while (!isspace(*cp)) + cp++; + while (isspace(*cp)) + cp++; + gy = atoi(cp); + fprintf(fp_err, "Position @ (%d, %d)\n", gx, gy); + continue; + } else if (strncmp(cp, "Fore", 4) == 0) { + cp += 4; + while (isspace(*cp)) + cp++; + color_names[c_fore] = CopyNString(cp, 0); + fprintf(fp_err, "ColorFore: %s\n", color_names[c_fore]); + continue; + } else if (strncmp(cp, "Back", 4) == 0) { + cp += 4; + while (isspace(*cp)) + cp++; + color_names[c_back] = CopyNString(cp, 0); + fprintf(fp_err, "ColorBack: %s\n", color_names[c_back]); + continue; + } else if (strncmp(cp, "ItemFore", 8) == 0) { + cp += 8; + while (isspace(*cp)) + cp++; + color_names[c_itemfore] = CopyNString(cp, 0); + fprintf(fp_err, "ColorItemFore: %s\n", + color_names[c_itemfore]); + continue; + } else if (strncmp(cp, "ItemBack", 8) == 0) { + cp += 8; + while (isspace(*cp)) + cp++; + color_names[c_itemback] = CopyNString(cp, 0); + fprintf(fp_err, "ColorItemBack: %s\n", + color_names[c_itemback]); + continue; + } else if (strncmp(cp, "Font", 4) == 0) { + cp += 4; + while (isspace(*cp)) + cp++; + font_names[f_text] = CopyNString(cp, 0); + fprintf(fp_err, "Font: %s\n", font_names[f_text]); + xfs[f_text] = GetFontOrFixed(dpy, font_names[f_text]); + fonts[f_text] = xfs[f_text]->fid; + continue; + } else if (strncmp(cp, "ButtonFont", 10) == 0) { + cp += 10; + while (isspace(*cp)) + cp++; + font_names[f_button] = CopyNString(cp, 0); + fprintf( + fp_err, "ButtonFont: %s\n", font_names[f_button]); + xfs[f_button] = + GetFontOrFixed(dpy, font_names[f_button]); + fonts[f_button] = xfs[f_button]->fid; + continue; + } else if (strncmp(cp, "InputFont", 9) == 0) { + cp += 9; + while (isspace(*cp)) + cp++; + font_names[f_input] = CopyNString(cp, 0); + fprintf(fp_err, "InputFont: %s\n", font_names[f_input]); + xfs[f_input] = GetFontOrFixed(dpy, font_names[f_input]); + fonts[f_input] = xfs[f_input]->fid; + continue; + } else if (strncmp(cp, "Line", 4) == 0) { + cp += 4; + if (n_lines == 0) { + cur_line = add_line(L_CENTER); + } else if (n_lines == 1 && lines[0].n == 0) { + cur_line = &lines[0]; + cur_line->n = 0; + cur_line->size_x = 0; + cur_line->size_y = 0; + } else { + cur_line = add_line(L_CENTER); + } + while (isspace(*cp)) + cp++; + if (strncmp(cp, "left", 4) == 0) + cur_line->justify = L_LEFT; + else if (strncmp(cp, "right", 5) == 0) + cur_line->justify = L_RIGHT; + else if (strncmp(cp, "center", 6) == 0) + cur_line->justify = L_CENTER; + else + cur_line->justify = L_LEFTRIGHT; + cur_line->n = 0; + cur_line->size_x = cur_line->size_y = 0; + continue; + } else if (strncmp(cp, "Text", 4) == 0) { + /* syntax: *FFText "" */ + cp += 4; + if (n_items + 1 > items_capacity) { + items_capacity = items_capacity ? + items_capacity * 2 : + INITIAL_ITEMS_CAPACITY; + items = (Item *)realloc( + items, sizeof(Item) * items_capacity); + } + item = &items[n_items++]; + item->type = I_TEXT; + item->header.name = ""; + while (isspace(*cp)) + cp++; + if (*cp == '\"') + item->text.value = CopyQuotedString(++cp); + else + item->text.value = ""; + item->text.n = strlen(item->text.value); + item->header.size_x = + XTextWidth( + xfs[f_text], item->text.value, item->text.n) + + 2 * TEXT_SPC; + item->header.size_y = + FontHeight(xfs[f_text]) + 2 * TEXT_SPC; + fprintf(fp_err, "Text \"%s\" [%d, %d]\n", + item->text.value, item->header.size_x, + item->header.size_y); + append_item_to_line(cur_line, item); + continue; + } else if (strncmp(cp, "Input", 5) == 0) { + /* syntax: *FFInput "" */ + cp += 5; + if (n_items + 1 > items_capacity) { + items_capacity = items_capacity ? + items_capacity * 2 : + INITIAL_ITEMS_CAPACITY; + items = (Item *)realloc( + items, sizeof(Item) * items_capacity); + } + item = &items[n_items++]; + item->type = I_INPUT; + while (isspace(*cp)) + cp++; + item->header.name = CopySolidString(cp); + cp += strlen(item->header.name); + while (isspace(*cp)) + cp++; + item->input.size = atoi(cp); + while (!isspace(*cp)) + cp++; + while (isspace(*cp)) + cp++; + if (*cp == '\"') + item->input.init_value = CopyQuotedString(++cp); + else + item->input.init_value = ""; + item->input.blanks = (char *)malloc(item->input.size); + for (j = 0; j < item->input.size; j++) + item->input.blanks[j] = ' '; + item->input.buf = strlen(item->input.init_value) + 1; + item->input.value = (char *)malloc(item->input.buf); + item->header.size_x = + FontWidth(xfs[f_input]) * item->input.size + + 2 * TEXT_SPC + 2 * BOX_SPC; + item->header.size_y = FontHeight(xfs[f_input]) + + 3 * TEXT_SPC + 2 * BOX_SPC; + fprintf(fp_err, "Input, %s, [%d], \"%s\"\n", + item->header.name, item->input.size, + item->input.init_value); + append_item_to_line(cur_line, item); + } else if (strncmp(cp, "Selection", 9) == 0) { + /* syntax: *FFSelection single | multiple */ + cp += 9; + if (n_items + 1 > items_capacity) { + items_capacity = items_capacity ? + items_capacity * 2 : + INITIAL_ITEMS_CAPACITY; + items = (Item *)realloc( + items, sizeof(Item) * items_capacity); + } + cur_sel = &items[n_items++]; + cur_sel->type = I_SELECT; + while (isspace(*cp)) + cp++; + cur_sel->header.name = CopySolidString(cp); + cp += strlen(cur_sel->header.name); + while (isspace(*cp)) + cp++; + if (strncmp(cp, "multiple", 8) == 0) + cur_sel->select.key = IS_MULTIPLE; + else + cur_sel->select.key = IS_SINGLE; + cur_sel->select.n = 0; + cur_sel->select.choices_cap = INITIAL_CHOICES_CAPACITY; + cur_sel->select.choices = (Item **)malloc( + sizeof(Item *) * cur_sel->select.choices_cap); + cur_sel->header.size_x = 0; + cur_sel->header.size_y = 0; + fprintf(fp_err, "Selection %s (%s)\n", + cur_sel->header.name, + (cur_sel->select.key == IS_MULTIPLE) ? "multiple" : + "single"); + continue; + } else if (strncmp(cp, "Choice", 6) == 0) { + /* syntax: *FFChoice on|off "" */ + cp += 6; + while (isspace(*cp)) + cp++; + if (cur_sel == NULL) { + fprintf(fp_err, "Choice specified before " + "Selection, skipping\n"); + continue; + } + if (cur_sel->select.n + 1 > + cur_sel->select.choices_cap) { + cur_sel->select.choices_cap *= 2; + cur_sel->select.choices = + (Item **)realloc(cur_sel->select.choices, + sizeof(Item *) * + cur_sel->select.choices_cap); + } + if (n_items + 1 > items_capacity) { + items_capacity = items_capacity ? + items_capacity * 2 : + INITIAL_ITEMS_CAPACITY; + items = (Item *)realloc( + items, sizeof(Item) * items_capacity); + } + item = &items[n_items++]; + item->type = I_CHOICE; + item->choice.sel = cur_sel; + item->header.name = CopySolidString(cp); + cp += strlen(item->header.name); + while (isspace(*cp)) + cp++; + item->choice.value = CopySolidString(cp); + cp += strlen(item->choice.value); + while (isspace(*cp)) + cp++; + if (strncmp(cp, "on", 2) == 0) { + item->choice.on = 1; + item->choice.init_on = 1; + } else { + item->choice.on = 0; + item->choice.init_on = 0; + } + while (!isspace(*cp) && *cp != '\0') + cp++; + while (isspace(*cp)) + cp++; + if (*cp == '"') + item->choice.text = CopyQuotedString(++cp); + else + item->choice.text = ""; + item->choice.n = strlen(item->choice.text); + cur_sel->select.choices[cur_sel->select.n++] = item; + item->header.size_y = + FontHeight(xfs[f_text]) + 2 * TEXT_SPC; + item->header.size_x = + FontHeight(xfs[f_text]) + 4 * TEXT_SPC + + XTextWidth( + xfs[f_text], item->choice.text, item->choice.n); + fprintf(fp_err, "Choice %s, \"%s\", [%d, %d]\n", + item->header.name, item->choice.text, + item->header.size_x, item->header.size_y); + append_item_to_line(cur_line, item); + continue; + } else if (strncmp(cp, "Button", 6) == 0) { + /* syntax: *FFButton continue | restart | quit "" + */ + cp += 6; + if (n_items + 1 > items_capacity) { + items_capacity = items_capacity ? + items_capacity * 2 : + INITIAL_ITEMS_CAPACITY; + items = (Item *)realloc( + items, sizeof(Item) * items_capacity); + } + item = &items[n_items++]; + item->type = I_BUTTON; + item->header.name = ""; + while (isspace(*cp)) + cp++; + if (strncmp(cp, "restart", 7) == 0) + item->button.key = IB_RESTART; + else if (strncmp(cp, "quit", 4) == 0) + item->button.key = IB_QUIT; + else + item->button.key = IB_CONTINUE; + while (!isspace(*cp)) + cp++; + while (isspace(*cp)) + cp++; + if (*cp == '\"') { + item->button.text = CopyQuotedString(++cp); + cp += strlen(item->button.text) + 1; + while (isspace(*cp)) + cp++; + } else + item->button.text = ""; + if (*cp == '^') + item->button.keypress = *(++cp) - '@'; + else if (*cp == 'F') + item->button.keypress = 256 + atoi(++cp); + else + item->button.keypress = -1; + item->button.len = strlen(item->button.text); + item->button.n = 0; + item->button.commands = + (char **)malloc(sizeof(char *) * 8); + item->button.commands_cap = 8; + item->header.size_y = FontHeight(xfs[f_button]) + + 2 * TEXT_SPC + 2 * BOX_SPC; + item->header.size_x = + 2 * TEXT_SPC + 2 * BOX_SPC + + XTextWidth(xfs[f_button], item->button.text, + item->button.len); + append_item_to_line(cur_line, item); + cur_button = item; + continue; + } else if (strncmp(cp, "Command", 7) == 0) { + /* syntax: *FFCommand */ + cp += 7; + while (isspace(*cp)) + cp++; + if (cur_button->button.n + 1 > + cur_button->button.commands_cap) { + cur_button->button.commands_cap *= 2; + cur_button->button.commands = (char **)realloc( + cur_button->button.commands, + sizeof(char *) * + cur_button->button.commands_cap); + } + cur_button->button.commands[cur_button->button.n++] = + CopyNString(cp, 0); + } + } /* end of switch() */ + /* get the geometry right */ + max_width = 0; + total_height = ITEM_VSPC; + for (l = 0; l < n_lines; l++) { + line = lines + l; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_y = total_height; + if (line->items[i]->header.size_y < line->size_y) + line->items[i]->header.pos_y += + (line->size_y - + line->items[i]->header.size_y) / + 2 + + 1; + } + total_height += ITEM_VSPC + line->size_y; + line->size_x += (line->n + 1) * ITEM_HSPC; + if (line->size_x > max_width) + max_width = line->size_x; + } + for (l = 0; l < n_lines; l++) { + int width; + line = lines + l; + fprintf(fp_err, "Line[%d], %d, %d items\n", l, line->justify, + line->n); + switch (line->justify) { + case L_LEFT: + width = ITEM_HSPC; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_x = width; + width += + ITEM_HSPC + line->items[i]->header.size_x; + } + break; + case L_RIGHT: + width = max_width - line->size_x + ITEM_HSPC; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_x = width; + width += + ITEM_HSPC + line->items[i]->header.size_x; + } + break; + case L_CENTER: + width = (max_width - line->size_x) / 2 + ITEM_HSPC; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_x = width; + fprintf(fp_err, + "Line[%d], Item[%d] @ (%d, %d)\n", l, i, + line->items[i]->header.pos_x, + line->items[i]->header.pos_y); + width += + ITEM_HSPC + line->items[i]->header.size_x; + } + break; + case L_LEFTRIGHT: + /* count the number of inputs on the line - the extra + * space will be shared amongst these if there are any, + * otherwise it will be added as space in between the + * elements + */ + extra = 0; + for (i = 0; i < line->n; i++) { + if (line->items[i]->type == I_INPUT) + extra++; + } + if (extra == 0) { + if (line->n < 2) { /* same as L_CENTER */ + width = (max_width - line->size_x) / 2 + + ITEM_HSPC; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_x = + width; + width += ITEM_HSPC + + line->items[i] + ->header.size_x; + } + } else { + extra = (max_width - line->size_x) / + (line->n - 1); + width = ITEM_HSPC; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_x = + width; + width += ITEM_HSPC + + line->items[i] + ->header.size_x + + extra; + } + } + } else { + extra = (max_width - line->size_x) / extra; + width = ITEM_HSPC; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_x = width; + if (line->items[i]->type == I_INPUT) + line->items[i]->header.size_x += + extra; + width += ITEM_HSPC + + line->items[i]->header.size_x; + } + } + break; + } + } } #define MAX_INTENSITY 65535 /* allocate color cells */ -void GetColors () +void +GetColors() { - Visual* visual = DefaultVisual(dpy, screen); - XColor xc_item; - int red, green, blue, tmp1, tmp2 ; - if (scr_depth < 8) { - colors[c_back] = colors[c_itemback] = WhitePixel(dpy, screen); - colors[c_fore] = colors[c_itemfore] = colors[c_itemlo] = colors[c_itemhi] - = BlackPixel(dpy, screen); - } else if (visual->class == TrueColor || - visual->class == StaticColor || - visual->class == StaticGray) { - if (XParseColor(dpy, d_cmap, color_names[c_fore], &xc_item) && - XAllocColor(dpy, d_cmap, &xc_item)) - colors[c_fore] = xc_item.pixel; - else - colors[c_fore] = BlackPixel(dpy, screen); - - if (XParseColor(dpy, d_cmap, color_names[c_back], &xc_item) && - XAllocColor(dpy, d_cmap, &xc_item)) - colors[c_back] = xc_item.pixel; - else - colors[c_back] = WhitePixel(dpy, screen); - - if (XParseColor(dpy, d_cmap, color_names[c_itemfore], &xc_item) && - XAllocColor(dpy, d_cmap, &xc_item)) - colors[c_itemfore] = xc_item.pixel; - else - colors[c_itemfore] = BlackPixel(dpy, screen); - - if (XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item) && - XAllocColor(dpy, d_cmap, &xc_item)) - colors[c_itemback] = xc_item.pixel; - else - colors[c_itemback] = WhitePixel(dpy, screen); - - InitPictureCMap(dpy,root); /* for shadow routines */ - colors[c_itemlo] = GetShadow(colors[c_itemback]); /* alloc shadow */ - colors[c_itemhi] = GetHilite(colors[c_itemback]); /* alloc shadow */ - } else if (!XAllocColorCells(dpy, d_cmap, 0, NULL, 0, colors, 6)) { - colors[c_back] = colors[c_itemback] = WhitePixel(dpy, screen); - colors[c_fore] = colors[c_itemfore] = colors[c_itemlo] = colors[c_itemhi] - = BlackPixel(dpy, screen); - } else { - XStoreNamedColor(dpy, d_cmap, color_names[c_fore], colors[c_fore], - DoRed | DoGreen | DoBlue); - XStoreNamedColor(dpy, d_cmap, color_names[c_back], colors[c_back], - DoRed | DoGreen | DoBlue); - XStoreNamedColor(dpy, d_cmap, color_names[c_itemfore], - colors[c_itemfore], DoRed | DoGreen | DoBlue); - XStoreNamedColor(dpy, d_cmap, color_names[c_itemback], - colors[c_itemback], DoRed | DoGreen | DoBlue); - XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item); - red = (int) xc_item.red ; - green = (int) xc_item.green ; - blue = (int) xc_item.blue ; - xc_item.red = (60 * red) / 100 ; - xc_item.green = (60 * green) / 100 ; - xc_item.blue = (60 * blue) / 100 ; - xc_item.pixel = colors[c_itemlo]; - xc_item.flags = DoRed | DoGreen | DoBlue; - XStoreColor(dpy, d_cmap, &xc_item); - XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item); - tmp1 = (14 * red) / 10 ; - if (tmp1 > MAX_INTENSITY) tmp1 = MAX_INTENSITY ; - tmp2 = (MAX_INTENSITY + red) / 2 ; - xc_item.red = (tmp1 > tmp2) ? tmp1 : tmp2 ; - tmp1 = (14 * green) / 10 ; - if (tmp1 > MAX_INTENSITY) tmp1 = MAX_INTENSITY ; - tmp2 = (MAX_INTENSITY + green) / 2 ; - xc_item.green = (tmp1 > tmp2) ? tmp1 : tmp2 ; - tmp1 = (14 * blue) / 10 ; - if (tmp1 > MAX_INTENSITY) tmp1 = MAX_INTENSITY ; - tmp2 = (MAX_INTENSITY + blue) / 2 ; - xc_item.blue = (tmp1 > tmp2) ? tmp1 : tmp2 ; - xc_item.pixel = colors[c_itemhi]; - xc_item.flags = DoRed | DoGreen | DoBlue; - XStoreColor(dpy, d_cmap, &xc_item); - } + Visual *visual = DefaultVisual(dpy, screen); + XColor xc_item; + int red, green, blue, tmp1, tmp2; + if (scr_depth < 8) { + colors[c_back] = colors[c_itemback] = WhitePixel(dpy, screen); + colors[c_fore] = colors[c_itemfore] = colors[c_itemlo] = + colors[c_itemhi] = BlackPixel(dpy, screen); + } else if (visual->class == TrueColor || visual->class == StaticColor || + visual->class == StaticGray) { + if (XParseColor(dpy, d_cmap, color_names[c_fore], &xc_item) && + XAllocColor(dpy, d_cmap, &xc_item)) + colors[c_fore] = xc_item.pixel; + else + colors[c_fore] = BlackPixel(dpy, screen); + + if (XParseColor(dpy, d_cmap, color_names[c_back], &xc_item) && + XAllocColor(dpy, d_cmap, &xc_item)) + colors[c_back] = xc_item.pixel; + else + colors[c_back] = WhitePixel(dpy, screen); + + if (XParseColor( + dpy, d_cmap, color_names[c_itemfore], &xc_item) && + XAllocColor(dpy, d_cmap, &xc_item)) + colors[c_itemfore] = xc_item.pixel; + else + colors[c_itemfore] = BlackPixel(dpy, screen); + + if (XParseColor( + dpy, d_cmap, color_names[c_itemback], &xc_item) && + XAllocColor(dpy, d_cmap, &xc_item)) + colors[c_itemback] = xc_item.pixel; + else + colors[c_itemback] = WhitePixel(dpy, screen); + + InitPictureCMap(dpy, root); /* for shadow routines */ + colors[c_itemlo] = + GetShadow(colors[c_itemback]); /* alloc shadow */ + colors[c_itemhi] = + GetHilite(colors[c_itemback]); /* alloc shadow */ + } else if (!XAllocColorCells(dpy, d_cmap, 0, NULL, 0, colors, 6)) { + colors[c_back] = colors[c_itemback] = WhitePixel(dpy, screen); + colors[c_fore] = colors[c_itemfore] = colors[c_itemlo] = + colors[c_itemhi] = BlackPixel(dpy, screen); + } else { + XStoreNamedColor(dpy, d_cmap, color_names[c_fore], + colors[c_fore], DoRed | DoGreen | DoBlue); + XStoreNamedColor(dpy, d_cmap, color_names[c_back], + colors[c_back], DoRed | DoGreen | DoBlue); + XStoreNamedColor(dpy, d_cmap, color_names[c_itemfore], + colors[c_itemfore], DoRed | DoGreen | DoBlue); + XStoreNamedColor(dpy, d_cmap, color_names[c_itemback], + colors[c_itemback], DoRed | DoGreen | DoBlue); + XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item); + red = (int)xc_item.red; + green = (int)xc_item.green; + blue = (int)xc_item.blue; + xc_item.red = (60 * red) / 100; + xc_item.green = (60 * green) / 100; + xc_item.blue = (60 * blue) / 100; + xc_item.pixel = colors[c_itemlo]; + xc_item.flags = DoRed | DoGreen | DoBlue; + XStoreColor(dpy, d_cmap, &xc_item); + XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item); + tmp1 = (14 * red) / 10; + if (tmp1 > MAX_INTENSITY) + tmp1 = MAX_INTENSITY; + tmp2 = (MAX_INTENSITY + red) / 2; + xc_item.red = (tmp1 > tmp2) ? tmp1 : tmp2; + tmp1 = (14 * green) / 10; + if (tmp1 > MAX_INTENSITY) + tmp1 = MAX_INTENSITY; + tmp2 = (MAX_INTENSITY + green) / 2; + xc_item.green = (tmp1 > tmp2) ? tmp1 : tmp2; + tmp1 = (14 * blue) / 10; + if (tmp1 > MAX_INTENSITY) + tmp1 = MAX_INTENSITY; + tmp2 = (MAX_INTENSITY + blue) / 2; + xc_item.blue = (tmp1 > tmp2) ? tmp1 : tmp2; + xc_item.pixel = colors[c_itemhi]; + xc_item.flags = DoRed | DoGreen | DoBlue; + XStoreColor(dpy, d_cmap, &xc_item); + } } /* reset all the values */ -void Restart () +void +Restart() { - int i; - Item *item; - - cur_text = NULL; - abs_cursor = rel_cursor = 0; - for (i = 0; i < n_items; i++) { - item = items + i; - switch (item->type) { - case I_INPUT: - if (!cur_text) - cur_text = item; - item->input.n = strlen(item->input.init_value); - strcpy(item->input.value, item->input.init_value); - item->input.left = 0; - item->input.o_cursor = 0; - break; - case I_CHOICE: - item->choice.on = item->choice.init_on; - break; - } - } + int i; + Item *item; + + cur_text = NULL; + abs_cursor = rel_cursor = 0; + for (i = 0; i < n_items; i++) { + item = items + i; + switch (item->type) { + case I_INPUT: + if (!cur_text) + cur_text = item; + size_t init_len = strlen(item->input.init_value); + item->input.n = init_len; + strlcpy(item->input.value, item->input.init_value, + item->input.buf); + item->input.left = 0; + item->input.o_cursor = 0; + break; + case I_CHOICE: + item->choice.on = item->choice.init_on; + break; + } + } } /* redraw the frame */ -void RedrawFrame () +void +RedrawFrame() { - int i, x, y; - Item *item; - - for (i = 0; i < n_items; i++) { - item = items + i; - switch (item->type) { - case I_TEXT: - x = item->header.pos_x + TEXT_SPC; - y = item->header.pos_y + TEXT_SPC + xfs[f_text]->ascent; - XDrawImageString(dpy, frame, gc_text, x, y, item->text.value, - item->text.n); - break; - case I_CHOICE: - x = item->header.pos_x + TEXT_SPC + item->header.size_y; - y = item->header.pos_y + TEXT_SPC + xfs[f_text]->ascent; - XDrawImageString(dpy, frame, gc_text, x, y, item->choice.text, - item->choice.n); - break; - } - } + int i, x, y; + Item *item; + + for (i = 0; i < n_items; i++) { + item = items + i; + switch (item->type) { + case I_TEXT: + x = item->header.pos_x + TEXT_SPC; + y = item->header.pos_y + TEXT_SPC + xfs[f_text]->ascent; + XDrawImageString(dpy, frame, gc_text, x, y, + item->text.value, item->text.n); + break; + case I_CHOICE: + x = item->header.pos_x + TEXT_SPC + item->header.size_y; + y = item->header.pos_y + TEXT_SPC + xfs[f_text]->ascent; + XDrawImageString(dpy, frame, gc_text, x, y, + item->choice.text, item->choice.n); + break; + } + } } /* redraw an item */ -void RedrawItem (Item *item, int click) +void +RedrawItem(Item *item, int click) { - int dx, dy, len, x; - static XSegment xsegs[4]; - - switch (item->type) { - case I_INPUT: - dx = item->header.size_x - 1; - dy = item->header.size_y - 1; - XSetForeground(dpy, gc_button, colors[c_itemlo]); - xsegs[0].x1 = 0, xsegs[0].y1 = 0; - xsegs[0].x2 = 0, xsegs[0].y2 = dy; - xsegs[1].x1 = 0, xsegs[1].y1 = 0; - xsegs[1].x2 = dx, xsegs[1].y2 = 0; - xsegs[2].x1 = 1, xsegs[2].y1 = 1; - xsegs[2].x2 = 1, xsegs[2].y2 = dy - 1; - xsegs[3].x1 = 1, xsegs[3].y1 = 1; - xsegs[3].x2 = dx - 1, xsegs[3].y2 = 1; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); - XSetForeground(dpy, gc_button, colors[c_itemhi]); - xsegs[0].x1 = 1, xsegs[0].y1 = dy; - xsegs[0].x2 = dx, xsegs[0].y2 = dy; - xsegs[1].x1 = 2, xsegs[1].y1 = dy - 1; - xsegs[1].x2 = dx, xsegs[1].y2 = dy - 1; - xsegs[2].x1 = dx, xsegs[2].y1 = 1; - xsegs[2].x2 = dx, xsegs[2].y2 = dy; - xsegs[3].x1 = dx - 1, xsegs[3].y1 = 2; - xsegs[3].x2 = dx - 1, xsegs[3].y2 = dy; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); - if (click) { - x = BOX_SPC + TEXT_SPC + FontWidth(xfs[f_input]) * abs_cursor - 1; - XSetForeground(dpy, gc_button, colors[c_itemback]); - XDrawLine(dpy, item->header.win, gc_button, - x, BOX_SPC, x, dy - BOX_SPC); - } - len = item->input.n - item->input.left; - if (len > item->input.size) - len = item->input.size; - else - XDrawImageString(dpy, item->header.win, gc_input, - BOX_SPC + TEXT_SPC + FontWidth(xfs[f_input]) * len, - BOX_SPC + TEXT_SPC + xfs[f_input]->ascent, - item->input.blanks, item->input.size - len); - XDrawImageString(dpy, item->header.win, gc_input, - BOX_SPC + TEXT_SPC, - BOX_SPC + TEXT_SPC + xfs[f_input]->ascent, - item->input.value + item->input.left, len); - if (item == cur_text && !click) { - x = BOX_SPC + TEXT_SPC + FontWidth(xfs[f_input]) * abs_cursor - 1; - XDrawLine(dpy, item->header.win, gc_input, - x, BOX_SPC, x, dy - BOX_SPC); - } - break; - case I_CHOICE: - dx = dy = item->header.size_y - 1; - if (item->choice.on) { - XSetForeground(dpy, gc_button, colors[c_itemfore]); - if (item->choice.sel->select.key == IS_MULTIPLE) { - xsegs[0].x1 = 5, xsegs[0].y1 = 5; - xsegs[0].x2 = dx - 5, xsegs[0].y2 = dy - 5; - xsegs[1].x1 = 5, xsegs[1].y1 = dy - 5; - xsegs[1].x2 = dx - 5, xsegs[1].y2 = 5; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 2); - } else { - XDrawArc(dpy, item->header.win, gc_button, - 5, 5, dx - 10, dy - 10, 0, 360 * 64); - } - } else - XClearWindow(dpy, item->header.win); - if (item->choice.on) - XSetForeground(dpy, gc_button, colors[c_itemlo]); - else - XSetForeground(dpy, gc_button, colors[c_itemhi]); - xsegs[0].x1 = 0, xsegs[0].y1 = 0; - xsegs[0].x2 = 0, xsegs[0].y2 = dy; - xsegs[1].x1 = 0, xsegs[1].y1 = 0; - xsegs[1].x2 = dx, xsegs[1].y2 = 0; - xsegs[2].x1 = 1, xsegs[2].y1 = 1; - xsegs[2].x2 = 1, xsegs[2].y2 = dy - 1; - xsegs[3].x1 = 1, xsegs[3].y1 = 1; - xsegs[3].x2 = dx - 1, xsegs[3].y2 = 1; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); - if (item->choice.on) - XSetForeground(dpy, gc_button, colors[c_itemhi]); - else - XSetForeground(dpy, gc_button, colors[c_itemlo]); - xsegs[0].x1 = 1, xsegs[0].y1 = dy; - xsegs[0].x2 = dx, xsegs[0].y2 = dy; - xsegs[1].x1 = 2, xsegs[1].y1 = dy - 1; - xsegs[1].x2 = dx, xsegs[1].y2 = dy - 1; - xsegs[2].x1 = dx, xsegs[2].y1 = 1; - xsegs[2].x2 = dx, xsegs[2].y2 = dy; - xsegs[3].x1 = dx - 1, xsegs[3].y1 = 2; - xsegs[3].x2 = dx - 1, xsegs[3].y2 = dy; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); - break; - case I_BUTTON: - dx = item->header.size_x - 1; - dy = item->header.size_y - 1; - if (click) - XSetForeground(dpy, gc_button, colors[c_itemlo]); - else - XSetForeground(dpy, gc_button, colors[c_itemhi]); - xsegs[0].x1 = 0, xsegs[0].y1 = 0; - xsegs[0].x2 = 0, xsegs[0].y2 = dy; - xsegs[1].x1 = 0, xsegs[1].y1 = 0; - xsegs[1].x2 = dx, xsegs[1].y2 = 0; - xsegs[2].x1 = 1, xsegs[2].y1 = 1; - xsegs[2].x2 = 1, xsegs[2].y2 = dy - 1; - xsegs[3].x1 = 1, xsegs[3].y1 = 1; - xsegs[3].x2 = dx - 1, xsegs[3].y2 = 1; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); - if (click) - XSetForeground(dpy, gc_button, colors[c_itemhi]); - else - XSetForeground(dpy, gc_button, colors[c_itemlo]); - xsegs[0].x1 = 1, xsegs[0].y1 = dy; - xsegs[0].x2 = dx, xsegs[0].y2 = dy; - xsegs[1].x1 = 2, xsegs[1].y1 = dy - 1; - xsegs[1].x2 = dx, xsegs[1].y2 = dy - 1; - xsegs[2].x1 = dx, xsegs[2].y1 = 1; - xsegs[2].x2 = dx, xsegs[2].y2 = dy; - xsegs[3].x1 = dx - 1, xsegs[3].y1 = 2; - xsegs[3].x2 = dx - 1, xsegs[3].y2 = dy; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); - XSetForeground(dpy, gc_button, colors[c_itemfore]); - XDrawImageString(dpy, item->header.win, gc_button, - BOX_SPC + TEXT_SPC, - BOX_SPC + TEXT_SPC + xfs[f_button]->ascent, - item->button.text, item->button.len); - break; - } - XFlush(dpy); + int dx, dy, len, x; + static XSegment xsegs[4]; + + switch (item->type) { + case I_INPUT: + dx = item->header.size_x - 1; + dy = item->header.size_y - 1; + XSetForeground(dpy, gc_button, colors[c_itemlo]); + xsegs[0].x1 = 0, xsegs[0].y1 = 0; + xsegs[0].x2 = 0, xsegs[0].y2 = dy; + xsegs[1].x1 = 0, xsegs[1].y1 = 0; + xsegs[1].x2 = dx, xsegs[1].y2 = 0; + xsegs[2].x1 = 1, xsegs[2].y1 = 1; + xsegs[2].x2 = 1, xsegs[2].y2 = dy - 1; + xsegs[3].x1 = 1, xsegs[3].y1 = 1; + xsegs[3].x2 = dx - 1, xsegs[3].y2 = 1; + XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); + XSetForeground(dpy, gc_button, colors[c_itemhi]); + xsegs[0].x1 = 1, xsegs[0].y1 = dy; + xsegs[0].x2 = dx, xsegs[0].y2 = dy; + xsegs[1].x1 = 2, xsegs[1].y1 = dy - 1; + xsegs[1].x2 = dx, xsegs[1].y2 = dy - 1; + xsegs[2].x1 = dx, xsegs[2].y1 = 1; + xsegs[2].x2 = dx, xsegs[2].y2 = dy; + xsegs[3].x1 = dx - 1, xsegs[3].y1 = 2; + xsegs[3].x2 = dx - 1, xsegs[3].y2 = dy; + XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); + if (click) { + x = BOX_SPC + TEXT_SPC + + FontWidth(xfs[f_input]) * abs_cursor - 1; + XSetForeground(dpy, gc_button, colors[c_itemback]); + XDrawLine(dpy, item->header.win, gc_button, x, BOX_SPC, + x, dy - BOX_SPC); + } + len = item->input.n - item->input.left; + if (len > item->input.size) + len = item->input.size; + else + XDrawImageString(dpy, item->header.win, gc_input, + BOX_SPC + TEXT_SPC + FontWidth(xfs[f_input]) * len, + BOX_SPC + TEXT_SPC + xfs[f_input]->ascent, + item->input.blanks, item->input.size - len); + XDrawImageString(dpy, item->header.win, gc_input, + BOX_SPC + TEXT_SPC, + BOX_SPC + TEXT_SPC + xfs[f_input]->ascent, + item->input.value + item->input.left, len); + if (item == cur_text && !click) { + x = BOX_SPC + TEXT_SPC + + FontWidth(xfs[f_input]) * abs_cursor - 1; + XDrawLine(dpy, item->header.win, gc_input, x, BOX_SPC, + x, dy - BOX_SPC); + } + break; + case I_CHOICE: + dx = dy = item->header.size_y - 1; + if (item->choice.on) { + XSetForeground(dpy, gc_button, colors[c_itemfore]); + if (item->choice.sel->select.key == IS_MULTIPLE) { + xsegs[0].x1 = 5, xsegs[0].y1 = 5; + xsegs[0].x2 = dx - 5, xsegs[0].y2 = dy - 5; + xsegs[1].x1 = 5, xsegs[1].y1 = dy - 5; + xsegs[1].x2 = dx - 5, xsegs[1].y2 = 5; + XDrawSegments( + dpy, item->header.win, gc_button, xsegs, 2); + } else { + XDrawArc(dpy, item->header.win, gc_button, 5, 5, + dx - 10, dy - 10, 0, 360 * 64); + } + } else + XClearWindow(dpy, item->header.win); + if (item->choice.on) + XSetForeground(dpy, gc_button, colors[c_itemlo]); + else + XSetForeground(dpy, gc_button, colors[c_itemhi]); + xsegs[0].x1 = 0, xsegs[0].y1 = 0; + xsegs[0].x2 = 0, xsegs[0].y2 = dy; + xsegs[1].x1 = 0, xsegs[1].y1 = 0; + xsegs[1].x2 = dx, xsegs[1].y2 = 0; + xsegs[2].x1 = 1, xsegs[2].y1 = 1; + xsegs[2].x2 = 1, xsegs[2].y2 = dy - 1; + xsegs[3].x1 = 1, xsegs[3].y1 = 1; + xsegs[3].x2 = dx - 1, xsegs[3].y2 = 1; + XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); + if (item->choice.on) + XSetForeground(dpy, gc_button, colors[c_itemhi]); + else + XSetForeground(dpy, gc_button, colors[c_itemlo]); + xsegs[0].x1 = 1, xsegs[0].y1 = dy; + xsegs[0].x2 = dx, xsegs[0].y2 = dy; + xsegs[1].x1 = 2, xsegs[1].y1 = dy - 1; + xsegs[1].x2 = dx, xsegs[1].y2 = dy - 1; + xsegs[2].x1 = dx, xsegs[2].y1 = 1; + xsegs[2].x2 = dx, xsegs[2].y2 = dy; + xsegs[3].x1 = dx - 1, xsegs[3].y1 = 2; + xsegs[3].x2 = dx - 1, xsegs[3].y2 = dy; + XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); + break; + case I_BUTTON: + dx = item->header.size_x - 1; + dy = item->header.size_y - 1; + if (click) + XSetForeground(dpy, gc_button, colors[c_itemlo]); + else + XSetForeground(dpy, gc_button, colors[c_itemhi]); + xsegs[0].x1 = 0, xsegs[0].y1 = 0; + xsegs[0].x2 = 0, xsegs[0].y2 = dy; + xsegs[1].x1 = 0, xsegs[1].y1 = 0; + xsegs[1].x2 = dx, xsegs[1].y2 = 0; + xsegs[2].x1 = 1, xsegs[2].y1 = 1; + xsegs[2].x2 = 1, xsegs[2].y2 = dy - 1; + xsegs[3].x1 = 1, xsegs[3].y1 = 1; + xsegs[3].x2 = dx - 1, xsegs[3].y2 = 1; + XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); + if (click) + XSetForeground(dpy, gc_button, colors[c_itemhi]); + else + XSetForeground(dpy, gc_button, colors[c_itemlo]); + xsegs[0].x1 = 1, xsegs[0].y1 = dy; + xsegs[0].x2 = dx, xsegs[0].y2 = dy; + xsegs[1].x1 = 2, xsegs[1].y1 = dy - 1; + xsegs[1].x2 = dx, xsegs[1].y2 = dy - 1; + xsegs[2].x1 = dx, xsegs[2].y1 = 1; + xsegs[2].x2 = dx, xsegs[2].y2 = dy; + xsegs[3].x1 = dx - 1, xsegs[3].y1 = 2; + xsegs[3].x2 = dx - 1, xsegs[3].y2 = dy; + XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); + XSetForeground(dpy, gc_button, colors[c_itemfore]); + XDrawImageString(dpy, item->header.win, gc_button, + BOX_SPC + TEXT_SPC, + BOX_SPC + TEXT_SPC + xfs[f_button]->ascent, + item->button.text, item->button.len); + break; + } + XFlush(dpy); } -void ToggleChoice (Item *item) +void +ToggleChoice(Item *item) { - int i; - Item *sel = item->choice.sel; - - if (sel->select.key == IS_SINGLE) { - if (!item->choice.on) { - for (i = 0; i < sel->select.n; i++) { - if (sel->select.choices[i]->choice.on) { - sel->select.choices[i]->choice.on = 0; - RedrawItem(sel->select.choices[i], 0); + int i; + Item *sel = item->choice.sel; + + if (sel->select.key == IS_SINGLE) { + if (!item->choice.on) { + for (i = 0; i < sel->select.n; i++) { + if (sel->select.choices[i]->choice.on) { + sel->select.choices[i]->choice.on = 0; + RedrawItem(sel->select.choices[i], 0); + } + } + item->choice.on = 1; + RedrawItem(item, 0); + } + } else { /* IS_MULTIPLE */ + item->choice.on = !item->choice.on; + RedrawItem(item, 0); } - } - item->choice.on = 1; - RedrawItem(item, 0); - } - } else { /* IS_MULTIPLE */ - item->choice.on = !item->choice.on; - RedrawItem(item, 0); - } } /* do var substitution for command string */ -void ParseCommand (int dn, char *sp, char end, int *dn1, char **sp1) -#define AddChar(chr) { if (dn >= N) { N *= 2; buf = (char *)realloc(buf, N); } buf[dn++] = (chr); } -{ - static char var[256]; - char c, x, *wp, *cp, *vp; - int i, j, dn2; - Item *item; - - while (1) { - c = *(sp++); - if (c == '\0' || c == end) { /* end of substitution */ - *dn1 = dn; - *sp1 = sp; - return; - } if (c == '\\') { /* escape char */ - AddChar('\\'); - AddChar(*(sp++)); - goto next_loop; - } - if (c == '$') { /* variable */ - if (*sp != '(') - goto normal_char; - wp = ++sp; - vp = var; - while (1) { - x = *(sp++); - if (x == '\\') { - *(vp++) = '\\'; - *(vp++) = *(sp++); - } - else if (x == ')' || x == '?' || x == '!') { - *(vp++) = '\0'; - break; +void +ParseCommand(int dn, char *sp, char end, int *dn1, char **sp1) +#define AddChar(chr) \ + { \ + if (dn >= N) { \ + N *= 2; \ + buf = (char *)realloc(buf, N); \ + } \ + buf[dn++] = (chr); \ } - else if (!isspace(x)) - *(vp++) = x; - } - for (i = 0; i < n_items; i++) { - item = items + i; - if (strcmp(var, item->header.name) == 0) { - switch (item->type) { - case I_INPUT: - if (x == ')') { - for (cp = item->input.value; *cp != '\0'; cp++) { - if (*cp == '\"' || *cp == '\'' || *cp == '\\') - AddChar('\\'); - AddChar(*cp); - } - } else { - ParseCommand(dn, sp, ')', &dn2, &sp); - if ((x == '?' && strlen(item->input.value) > 0) || - (x == '!' && strlen(item->input.value) == 0)) - dn = dn2; - } - break; - case I_CHOICE: - if (x == ')') { - for (cp = item->choice.value; *cp != '\0'; cp++) - AddChar(*cp); - } else { - ParseCommand(dn, sp, ')', &dn2, &sp); - if ((x == '?' && item->choice.on) || - (x == '!' && !item->choice.on)) - dn = dn2; - } - break; - case I_SELECT: - if (x != ')') - ParseCommand(dn, sp, ')', &dn2, &sp); - AddChar(' '); - for (j = 0; j < item->select.n; j++) { - if (item->select.choices[j]->choice.on) { - for (cp = item->select.choices[j]->choice.value; - *cp != '\0'; cp++) - AddChar(*cp); - AddChar(' '); - } - } - break; - } - goto next_loop; +{ + static char var[256]; + char c, x, *wp, *cp, *vp; + int i, j, dn2; + Item *item; + + while (1) { + c = *(sp++); + if (c == '\0' || c == end) { /* end of substitution */ + *dn1 = dn; + *sp1 = sp; + return; + } + if (c == '\\') { /* escape char */ + AddChar('\\'); + AddChar(*(sp++)); + goto next_loop; + } + if (c == '$') { /* variable */ + if (*sp != '(') + goto normal_char; + wp = ++sp; + vp = var; + while (1) { + x = *(sp++); + if (x == '\\') { + *(vp++) = '\\'; + *(vp++) = *(sp++); + } else if (x == ')' || x == '?' || x == '!') { + *(vp++) = '\0'; + break; + } else if (!isspace(x)) + *(vp++) = x; + } + for (i = 0; i < n_items; i++) { + item = items + i; + if (strcmp(var, item->header.name) == 0) { + switch (item->type) { + case I_INPUT: + if (x == ')') { + for (cp = item->input + .value; + *cp != '\0'; cp++) { + if (*cp == + '\"' || + *cp == + '\'' || + *cp == '\\') + AddChar( + '\\'); + AddChar(*cp); + } + } else { + ParseCommand(dn, sp, + ')', &dn2, &sp); + if ((x == '?' && + strlen( + item->input + .value) > + 0) || + (x == '!' && + strlen( + item->input + .value) == + 0)) + dn = dn2; + } + break; + case I_CHOICE: + if (x == ')') { + for (cp = item->choice + .value; + *cp != '\0'; cp++) + AddChar(*cp); + } else { + ParseCommand(dn, sp, + ')', &dn2, &sp); + if ((x == '?' && + item->choice + .on) || + (x == '!' && + !item->choice + .on)) + dn = dn2; + } + break; + case I_SELECT: + if (x != ')') + ParseCommand(dn, sp, + ')', &dn2, &sp); + AddChar(' '); + for (j = 0; j < item->select.n; + j++) { + if (item->select + .choices[j] + ->choice.on) { + for (cp = item + ->select + .choices + [j] + ->choice + .value; + *cp != '\0'; + cp++) + AddChar( + *cp); + AddChar(' '); + } + } + break; + } + goto next_loop; + } + } + goto next_loop; + } + normal_char: + AddChar(c); + next_loop: ; } - } - goto next_loop; - } - normal_char: - AddChar(c); - next_loop: - ; - } } /* execute a command */ -void DoCommand (Item *cmd) +void +DoCommand(Item *cmd) { - int i, k, dn, len; - char *sp; - - /* pre-command */ - if (cmd->button.key == IB_QUIT) - XWithdrawWindow(dpy, frame, screen); - - for (k = 0; k < cmd->button.n; k++) { - /* construct command */ - ParseCommand(0, cmd->button.commands[k], '\0', &dn, &sp); - AddChar('\0'); - fprintf(fp_err, "Final command[%d]: [%s]\n", k, buf); - - /* send command */ - write(fd_out, &ref, sizeof(Window)); - len = strlen(buf); - write(fd_out, &len, sizeof(int)); - write(fd_out, buf, len); - len = 1; - write(fd_out, &len, sizeof(int)); - } - - /* post-command */ - if (cmd->button.key == IB_QUIT) { - if (grab_server) - XUngrabServer(dpy); - exit(0); - } - if (cmd->button.key == IB_RESTART) { - Restart(); - for (i = 0; i < n_items; i++) { - if (items[i].type == I_INPUT) { - XClearWindow(dpy, items[i].header.win); - RedrawItem(items + i, 0); - } - if (items[i].type == I_CHOICE) - RedrawItem(items + i, 0); - } - } + int i, k, dn, len; + char *sp; + + /* pre-command */ + if (cmd->button.key == IB_QUIT) + XWithdrawWindow(dpy, frame, screen); + + for (k = 0; k < cmd->button.n; k++) { + /* construct command */ + ParseCommand(0, cmd->button.commands[k], '\0', &dn, &sp); + AddChar('\0'); + fprintf(fp_err, "Final command[%d]: [%s]\n", k, buf); + + /* send command */ + write(fd_out, &ref, sizeof(Window)); + len = strlen(buf); + write(fd_out, &len, sizeof(int)); + write(fd_out, buf, len); + len = 1; + write(fd_out, &len, sizeof(int)); + } + + /* post-command */ + if (cmd->button.key == IB_QUIT) { + if (grab_server) + XUngrabServer(dpy); + exit(0); + } + if (cmd->button.key == IB_RESTART) { + Restart(); + for (i = 0; i < n_items; i++) { + if (items[i].type == I_INPUT) { + XClearWindow(dpy, items[i].header.win); + RedrawItem(items + i, 0); + } + if (items[i].type == I_CHOICE) + RedrawItem(items + i, 0); + } + } } /* open the windows */ -void OpenWindows () +void +OpenWindows() { - int i, x, y; - Item *item; - static XColor xcf, xcb; - static XSetWindowAttributes xswa; - static XGCValues xgcv; - static XWMHints wmh = { InputHint, True }; - static XSizeHints sh = { PPosition | PSize | USPosition | USSize }; - static int xgcv_mask = GCBackground | GCForeground | GCFont; - - xc_ibeam = XCreateFontCursor(dpy, XC_xterm); - xc_hand = XCreateFontCursor(dpy, XC_hand2); - xcf.pixel = WhitePixel(dpy, screen); - XQueryColor(dpy, d_cmap, &xcf); - xcb.pixel = colors[c_itemback]; - XQueryColor(dpy, d_cmap, &xcb); - XRecolorCursor(dpy, xc_ibeam, &xcf, &xcb); - - /* the frame window first */ - if (geom) { - if (gx >= 0) - x = gx; - else - x = DisplayWidth(dpy, screen) - max_width + gx; - if (gy >= 0) - y = gy; - else - y = DisplayHeight(dpy, screen) - total_height + gy; - } else { - x = (DisplayWidth(dpy, screen) - max_width) / 2; - y = (DisplayHeight(dpy, screen) - total_height) / 2; - } - frame = XCreateSimpleWindow(dpy, root, x, y, max_width, total_height, - 0, BlackPixel(dpy, screen), colors[c_back]); - XSelectInput(dpy, frame, KeyPressMask | ExposureMask); - XStoreName(dpy, frame, prog_name); - XSetWMHints(dpy, frame, &wmh); - sh.x = x, sh.y = y; - sh.width = max_width, sh.height = total_height; - XSetWMNormalHints(dpy, frame, &sh); - - xgcv.foreground = colors[c_fore]; - xgcv.background = colors[c_back]; - xgcv.font = fonts[f_text]; - gc_text = XCreateGC(dpy, frame, xgcv_mask, &xgcv); - xgcv.background = colors[c_itemback]; - xgcv.foreground = colors[c_itemfore]; - xgcv.font = fonts[f_input]; - gc_input = XCreateGC(dpy, frame, xgcv_mask, &xgcv); - xgcv.font = fonts[f_button]; - gc_button = XCreateGC(dpy, frame, xgcv_mask, &xgcv); - - for (i = 0; i < n_items; i++) { - item = items + i; - switch (item->type) { - case I_INPUT: - item->header.win = - XCreateSimpleWindow(dpy, frame, + int i, x, y; + Item *item; + static XColor xcf, xcb; + static XSetWindowAttributes xswa; + static XGCValues xgcv; + static XWMHints wmh = {InputHint, True}; + static XSizeHints sh = {PPosition | PSize | USPosition | USSize}; + static int xgcv_mask = GCBackground | GCForeground | GCFont; + + xc_ibeam = XCreateFontCursor(dpy, XC_xterm); + xc_hand = XCreateFontCursor(dpy, XC_hand2); + xcf.pixel = WhitePixel(dpy, screen); + XQueryColor(dpy, d_cmap, &xcf); + xcb.pixel = colors[c_itemback]; + XQueryColor(dpy, d_cmap, &xcb); + XRecolorCursor(dpy, xc_ibeam, &xcf, &xcb); + + /* the frame window first */ + if (geom) { + if (gx >= 0) + x = gx; + else + x = DisplayWidth(dpy, screen) - max_width + gx; + if (gy >= 0) + y = gy; + else + y = DisplayHeight(dpy, screen) - total_height + gy; + } else { + x = (DisplayWidth(dpy, screen) - max_width) / 2; + y = (DisplayHeight(dpy, screen) - total_height) / 2; + } + frame = XCreateSimpleWindow(dpy, root, x, y, max_width, total_height, 0, + BlackPixel(dpy, screen), colors[c_back]); + XSelectInput(dpy, frame, KeyPressMask | ExposureMask); + XStoreName(dpy, frame, prog_name); + XSetWMHints(dpy, frame, &wmh); + sh.x = x, sh.y = y; + sh.width = max_width, sh.height = total_height; + XSetWMNormalHints(dpy, frame, &sh); + + xgcv.foreground = colors[c_fore]; + xgcv.background = colors[c_back]; + xgcv.font = fonts[f_text]; + gc_text = XCreateGC(dpy, frame, xgcv_mask, &xgcv); + xgcv.background = colors[c_itemback]; + xgcv.foreground = colors[c_itemfore]; + xgcv.font = fonts[f_input]; + gc_input = XCreateGC(dpy, frame, xgcv_mask, &xgcv); + xgcv.font = fonts[f_button]; + gc_button = XCreateGC(dpy, frame, xgcv_mask, &xgcv); + + for (i = 0; i < n_items; i++) { + item = items + i; + switch (item->type) { + case I_INPUT: + item->header.win = XCreateSimpleWindow(dpy, frame, item->header.pos_x, item->header.pos_y, - item->header.size_x, item->header.size_y, - 0, colors[c_back], colors[c_itemback]); - XSelectInput(dpy, item->header.win, ButtonPressMask | ExposureMask); - xswa.cursor = xc_ibeam; - XChangeWindowAttributes(dpy, item->header.win, CWCursor, &xswa); - break; - case I_CHOICE: - item->header.win = - XCreateSimpleWindow(dpy, frame, + item->header.size_x, item->header.size_y, 0, + colors[c_back], colors[c_itemback]); + XSelectInput(dpy, item->header.win, + ButtonPressMask | ExposureMask); + xswa.cursor = xc_ibeam; + XChangeWindowAttributes( + dpy, item->header.win, CWCursor, &xswa); + break; + case I_CHOICE: + item->header.win = XCreateSimpleWindow(dpy, frame, item->header.pos_x, item->header.pos_y, - item->header.size_y, item->header.size_y, - 0, colors[c_back], colors[c_itemback]); - XSelectInput(dpy, item->header.win, ButtonPressMask | ExposureMask); - xswa.cursor = xc_hand; - XChangeWindowAttributes(dpy, item->header.win, CWCursor, &xswa); - break; - case I_BUTTON: - item->header.win = - XCreateSimpleWindow(dpy, frame, + item->header.size_y, item->header.size_y, 0, + colors[c_back], colors[c_itemback]); + XSelectInput(dpy, item->header.win, + ButtonPressMask | ExposureMask); + xswa.cursor = xc_hand; + XChangeWindowAttributes( + dpy, item->header.win, CWCursor, &xswa); + break; + case I_BUTTON: + item->header.win = XCreateSimpleWindow(dpy, frame, item->header.pos_x, item->header.pos_y, - item->header.size_x, item->header.size_y, - 0, colors[c_back], colors[c_itemback]); - XSelectInput(dpy, item->header.win, - ButtonPressMask | ExposureMask); - xswa.cursor = xc_hand; - XChangeWindowAttributes(dpy, item->header.win, CWCursor, &xswa); - break; - } - } - Restart(); - XMapRaised(dpy, frame); - XMapSubwindows(dpy, frame); - if (warp_pointer) { - XWarpPointer(dpy, None, frame, 0, 0, 0, 0, - max_width / 2, total_height - 1); - } - DoCommand(&def_button); + item->header.size_x, item->header.size_y, 0, + colors[c_back], colors[c_itemback]); + XSelectInput(dpy, item->header.win, + ButtonPressMask | ExposureMask); + xswa.cursor = xc_hand; + XChangeWindowAttributes( + dpy, item->header.win, CWCursor, &xswa); + break; + } + } + Restart(); + XMapRaised(dpy, frame); + XMapSubwindows(dpy, frame); + if (warp_pointer) { + XWarpPointer(dpy, None, frame, 0, 0, 0, 0, max_width / 2, + total_height - 1); + } + DoCommand(&def_button); } /* read something from Fvwm */ -void ReadFvwm () +void +ReadFvwm() { - static char buffer[32]; - int n; - - n = read(fd_in, buffer, 32); - if (n == 0) { - if (grab_server) - XUngrabServer(dpy); - exit(0); - } + static char buffer[32]; + int n; + + n = read(fd_in, buffer, 32); + if (n == 0) { + if (grab_server) + XUngrabServer(dpy); + exit(0); + } } /* read an X event */ -void ReadXServer () +void +ReadXServer() { - static XEvent event; - int i, old_cursor, keypress; - Item *item, *old_item; - KeySym ks; - char *sp, *dp, *ep; - static unsigned char buf[10], n; - - while (XEventsQueued(dpy, QueuedAfterReading)) { - XNextEvent(dpy, &event); - if (event.xany.window == frame) { - switch (event.type) { - case Expose: - RedrawFrame(); - if (grab_server && !server_grabbed) { - if (GrabSuccess == - XGrabPointer(dpy, frame, True, 0, GrabModeAsync, GrabModeAsync, - None, None, CurrentTime)) - server_grabbed = 1; - } - break; - case KeyPress: /* we do text input here */ - n = XLookupString(&event.xkey, buf, 10, &ks, NULL); - keypress = buf[0]; - fprintf(fp_err, "Keypress [%s]\n", buf); - if (n == 0) { /* not a regular key, translate it into one */ - switch (ks) { - case XK_Home: - case XK_Begin: - buf[0] = '\001'; /* ^A */ - break; - case XK_End: - buf[0] = '\005'; /* ^E */ - break; - case XK_Left: - buf[0] = '\002'; /* ^B */ - break; - case XK_Right: - buf[0] = '\006'; /* ^F */ - break; - case XK_Up: - buf[0] = '\020'; /* ^P */ - break; - case XK_Down: - buf[0] = '\016'; /* ^N */ - break; - default: - if (ks >= XK_F1 && ks <= XK_F35) { - buf[0] = '\0'; - keypress = 257 + ks - XK_F1; - } else - goto no_redraw; /* no action for this event */ - } - } - if (!cur_text) { /* no text input fields */ - for (i = 0; i < n_items; i++) { - item = items + i; - fprintf(fp_err, "Button[%d], keypress==%d\n", i, - item->button.keypress); - if (item->type == I_BUTTON && item->button.keypress == buf[0]) { - RedrawItem(item, 1); - sleep(1); - RedrawItem(item, 0); - DoCommand(item); - goto no_redraw; - } - } - break; - } - switch (buf[0]) { - case '\001': /* ^A */ - old_cursor = abs_cursor; - rel_cursor = 0; - abs_cursor = 0; - cur_text->input.left = 0; - goto redraw_newcursor; - break; - case '\005': /* ^E */ - old_cursor = abs_cursor; - rel_cursor = cur_text->input.n; - if ((cur_text->input.left = rel_cursor - cur_text->input.size) < 0) - cur_text->input.left = 0; - abs_cursor = rel_cursor - cur_text->input.left; - goto redraw_newcursor; - break; - case '\002': /* ^B */ - old_cursor = abs_cursor; - if (rel_cursor > 0) { - rel_cursor--; - abs_cursor--; - if (abs_cursor <= 0 && rel_cursor > 0) { - abs_cursor++; - cur_text->input.left--; - } - } - goto redraw_newcursor; - break; - case '\006': /* ^F */ - old_cursor = abs_cursor; - if (rel_cursor < cur_text->input.n) { - rel_cursor++; - abs_cursor++; - if (abs_cursor >= cur_text->input.size && - rel_cursor < cur_text->input.n) { - abs_cursor--; - cur_text->input.left++; - } - } - goto redraw_newcursor; - break; - case '\010': /* ^H */ - old_cursor = abs_cursor; - if (rel_cursor > 0) { - sp = cur_text->input.value + rel_cursor; - dp = sp - 1; - for (; *dp = *sp, *sp != '\0'; dp++, sp++); - cur_text->input.n--; - rel_cursor--; - if (rel_cursor < abs_cursor) { - abs_cursor--; - if (abs_cursor <= 0 && rel_cursor > 0) { - abs_cursor++; - cur_text->input.left--; - } - } else - cur_text->input.left--; - } - goto redraw_newcursor; - break; - case '\177': /* DEL */ - case '\004': /* ^D */ - if (rel_cursor < cur_text->input.n) { - sp = cur_text->input.value + rel_cursor + 1; - dp = sp - 1; - for (; *dp = *sp, *sp != '\0'; dp++, sp++); - cur_text->input.n--; - goto redraw; - } - break; - case '\013': /* ^K */ - cur_text->input.value[rel_cursor] = '\0'; - cur_text->input.n = rel_cursor; - goto redraw; - case '\025': /* ^U */ - old_cursor = abs_cursor; - cur_text->input.value[0] = '\0'; - cur_text->input.n = cur_text->input.left = 0; - rel_cursor = abs_cursor = 0; - goto redraw_newcursor; - case '\t': - case '\n': - case '\015': - case '\016': /* LINEFEED, TAB, RETURN, ^N, jump to the next field */ - for (i = (cur_text - items) + 1; i < n_items; i++) { - item = items + i; - if (item->type == I_INPUT) { - old_item = cur_text; - old_item->input.o_cursor = rel_cursor; - cur_text = item; - RedrawItem(old_item, 1); - rel_cursor = item->input.o_cursor; - abs_cursor = rel_cursor - item->input.left; - goto redraw; - } - } - /* end of all text input fields, check for buttons */ - for (i = 0; i < n_items; i++) { - item = items + i; - fprintf(fp_err, "Button[%d], keypress==%d\n", i, - item->button.keypress); - if (item->type == I_BUTTON && item->button.keypress == buf[0]) { - RedrawItem(item, 1); - sleep(1); - RedrawItem(item, 0); - DoCommand(item); - goto no_redraw; - } - } - /* goto the first text input field */ - for (i = 0; i < n_items; i++) { - item = items + i; - if (item->type == I_INPUT) { - old_item = cur_text; - old_item->input.o_cursor = rel_cursor; - cur_text = item; - RedrawItem(old_item, 1); - rel_cursor = item->input.o_cursor; - abs_cursor = rel_cursor - item->input.left; - goto redraw; - } - } - break; - default: - old_cursor = abs_cursor; - if((buf[0] >= ' ' && - buf[0] < '\177') || - (buf[0] >= 160)) { /* regular or intl char */ - if (++(cur_text->input.n) >= cur_text->input.buf) { - cur_text->input.buf += cur_text->input.size; - cur_text->input.value = - (char *)realloc(cur_text->input.value, - cur_text->input.buf); - } - dp = cur_text->input.value + cur_text->input.n; - sp = dp - 1; - ep = cur_text->input.value + rel_cursor; - for (; *dp = *sp, sp != ep; sp--, dp--); - *ep = buf[0]; - rel_cursor++; - abs_cursor++; - if (abs_cursor >= cur_text->input.size) { - if (rel_cursor < cur_text->input.n) - abs_cursor = cur_text->input.size - 1; - else - abs_cursor = cur_text->input.size; - cur_text->input.left = rel_cursor - abs_cursor; - } - goto redraw_newcursor; - } - /* unrecognized key press, check for buttons */ - for (i = 0; i < n_items; i++) { - item = items + i; - fprintf(fp_err, "Button[%d], keypress==%d\n", i, - item->button.keypress); - if (item->type == I_BUTTON && item->button.keypress == keypress) { - RedrawItem(item, 1); - sleep(1); /* .5 seconds */ - RedrawItem(item, 0); - DoCommand(item); - goto no_redraw; - } - } - break; - } - redraw_newcursor: - { - int x, dy; - x = BOX_SPC + TEXT_SPC + FontWidth(xfs[f_input]) * old_cursor - 1; - dy = cur_text->header.size_y - 1; - XSetForeground(dpy, gc_button, colors[c_itemback]); - XDrawLine(dpy, cur_text->header.win, gc_button, - x, BOX_SPC, x, dy - BOX_SPC); - } - redraw: - { - int len, x, dy; - len = cur_text->input.n - cur_text->input.left; - if (len > cur_text->input.size) - len = cur_text->input.size; - else - XDrawImageString(dpy, cur_text->header.win, gc_input, - BOX_SPC + TEXT_SPC + - FontWidth(xfs[f_input]) * len, - BOX_SPC + TEXT_SPC + xfs[f_input]->ascent, - cur_text->input.blanks, - cur_text->input.size - len); - XDrawImageString(dpy, cur_text->header.win, gc_input, - BOX_SPC + TEXT_SPC, - BOX_SPC + TEXT_SPC + xfs[f_input]->ascent, - cur_text->input.value + cur_text->input.left, len); - x = BOX_SPC + TEXT_SPC + FontWidth(xfs[f_input]) * abs_cursor - 1; - dy = cur_text->header.size_y - 1; - XDrawLine(dpy, cur_text->header.win, gc_input, - x, BOX_SPC, x, dy - BOX_SPC); - } - no_redraw: - break; /* end of case KeyPress */ - } /* end of switch (event.type) */ - continue; - } /* end of if (event.xany.window == frame) */ - for (i = 0; i < n_items; i++) { - item = items + i; - if (event.xany.window == item->header.win) { - switch (event.type) { - case Expose: - RedrawItem(item, 0); - break; - case ButtonPress: - if (item->type == I_INPUT) { - old_item = cur_text; - old_item->input.o_cursor = rel_cursor; - cur_text = item; - RedrawItem(old_item, 1); - abs_cursor = (event.xbutton.x - BOX_SPC - - TEXT_SPC + FontWidth(xfs[f_input]) / 2) - / FontWidth(xfs[f_input]); - if (abs_cursor < 0) - abs_cursor = 0; - if (abs_cursor > item->input.size) - abs_cursor = item->input.size; - rel_cursor = abs_cursor + item->input.left; - if (rel_cursor < 0) - rel_cursor = 0; - if (rel_cursor > item->input.n) - rel_cursor = item->input.n; - if (rel_cursor > 0 && rel_cursor == item->input.left) - item->input.left--; - if (rel_cursor < item->input.n && - rel_cursor == item->input.left + item->input.size) - item->input.left++; - abs_cursor = rel_cursor - item->input.left; - RedrawItem(item, 0); - } - if (item->type == I_CHOICE) - ToggleChoice(item); - if (item->type == I_BUTTON) { - RedrawItem(item, 1); - XGrabPointer(dpy, item->header.win, False, ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, - None, None, CurrentTime); - } - break; - case ButtonRelease: - RedrawItem(item, 0); - if (grab_server && server_grabbed) { - XGrabPointer(dpy, frame, True, 0, GrabModeAsync, GrabModeAsync, - None, None, CurrentTime); - XFlush(dpy); - } else { - XUngrabPointer(dpy, CurrentTime); - XFlush(dpy); - } - if (event.xbutton.x >= 0 && - event.xbutton.x < item->header.size_x && - event.xbutton.y >= 0 && - event.xbutton.y < item->header.size_y) { - DoCommand(item); - } - break; - } - } - } /* end of for (i = 0 */ - } /* while loop */ + static XEvent event; + int i, old_cursor, keypress; + Item *item, *old_item; + KeySym ks; + char *sp, *dp, *ep; + static unsigned char buf[10], n; + + while (XEventsQueued(dpy, QueuedAfterReading)) { + XNextEvent(dpy, &event); + if (event.xany.window == frame) { + switch (event.type) { + case Expose: + RedrawFrame(); + if (grab_server && !server_grabbed) { + if (GrabSuccess == + XGrabPointer(dpy, frame, True, 0, + GrabModeAsync, GrabModeAsync, + None, None, CurrentTime)) + server_grabbed = 1; + } + break; + case KeyPress: /* we do text input here */ + n = XLookupString( + &event.xkey, buf, 10, &ks, NULL); + keypress = buf[0]; + fprintf(fp_err, "Keypress [%s]\n", buf); + if (n == 0) { /* not a regular key, translate it + into one */ + switch (ks) { + case XK_Home: + case XK_Begin: + buf[0] = '\001'; /* ^A */ + break; + case XK_End: + buf[0] = '\005'; /* ^E */ + break; + case XK_Left: + buf[0] = '\002'; /* ^B */ + break; + case XK_Right: + buf[0] = '\006'; /* ^F */ + break; + case XK_Up: + buf[0] = '\020'; /* ^P */ + break; + case XK_Down: + buf[0] = '\016'; /* ^N */ + break; + default: + if (ks >= XK_F1 && + ks <= XK_F35) { + buf[0] = '\0'; + keypress = + 257 + ks - XK_F1; + } else + goto no_redraw; /* no + action + for + this + event + */ + } + } + if (!cur_text) { /* no text input fields */ + for (i = 0; i < n_items; i++) { + item = items + i; + fprintf(fp_err, + "Button[%d], " + "keypress==%d\n", + i, item->button.keypress); + if (item->type == I_BUTTON && + item->button.keypress == + buf[0]) { + RedrawItem(item, 1); + sleep(1); + RedrawItem(item, 0); + DoCommand(item); + goto no_redraw; + } + } + break; + } + switch (buf[0]) { + case '\001': /* ^A */ + old_cursor = abs_cursor; + rel_cursor = 0; + abs_cursor = 0; + cur_text->input.left = 0; + goto redraw_newcursor; + break; + case '\005': /* ^E */ + old_cursor = abs_cursor; + rel_cursor = cur_text->input.n; + if ((cur_text->input.left = + rel_cursor - + cur_text->input.size) < 0) + cur_text->input.left = 0; + abs_cursor = + rel_cursor - cur_text->input.left; + goto redraw_newcursor; + break; + case '\002': /* ^B */ + old_cursor = abs_cursor; + if (rel_cursor > 0) { + rel_cursor--; + abs_cursor--; + if (abs_cursor <= 0 && + rel_cursor > 0) { + abs_cursor++; + cur_text->input.left--; + } + } + goto redraw_newcursor; + break; + case '\006': /* ^F */ + old_cursor = abs_cursor; + if (rel_cursor < cur_text->input.n) { + rel_cursor++; + abs_cursor++; + if (abs_cursor >= + cur_text->input.size && + rel_cursor < + cur_text->input.n) { + abs_cursor--; + cur_text->input.left++; + } + } + goto redraw_newcursor; + break; + case '\010': /* ^H */ + old_cursor = abs_cursor; + if (rel_cursor > 0) { + sp = cur_text->input.value + + rel_cursor; + dp = sp - 1; + for (; *dp = *sp, *sp != '\0'; + dp++, sp++) + ; + cur_text->input.n--; + rel_cursor--; + if (rel_cursor < abs_cursor) { + abs_cursor--; + if (abs_cursor <= 0 && + rel_cursor > 0) { + abs_cursor++; + cur_text->input + .left--; + } + } else + cur_text->input.left--; + } + goto redraw_newcursor; + break; + case '\177': /* DEL */ + case '\004': /* ^D */ + if (rel_cursor < cur_text->input.n) { + sp = cur_text->input.value + + rel_cursor + 1; + dp = sp - 1; + for (; *dp = *sp, *sp != '\0'; + dp++, sp++) + ; + cur_text->input.n--; + goto redraw; + } + break; + case '\013': /* ^K */ + cur_text->input.value[rel_cursor] = + '\0'; + cur_text->input.n = rel_cursor; + goto redraw; + case '\025': /* ^U */ + old_cursor = abs_cursor; + cur_text->input.value[0] = '\0'; + cur_text->input.n = + cur_text->input.left = 0; + rel_cursor = abs_cursor = 0; + goto redraw_newcursor; + case '\t': + case '\n': + case '\015': + case '\016': /* LINEFEED, TAB, RETURN, ^N, jump + to the next field */ + for (i = (cur_text - items) + 1; + i < n_items; i++) { + item = items + i; + if (item->type == I_INPUT) { + old_item = cur_text; + old_item->input + .o_cursor = + rel_cursor; + cur_text = item; + RedrawItem(old_item, 1); + rel_cursor = + item->input + .o_cursor; + abs_cursor = + rel_cursor - + item->input.left; + goto redraw; + } + } + /* end of all text input fields, check + * for buttons */ + for (i = 0; i < n_items; i++) { + item = items + i; + fprintf(fp_err, + "Button[%d], " + "keypress==%d\n", + i, item->button.keypress); + if (item->type == I_BUTTON && + item->button.keypress == + buf[0]) { + RedrawItem(item, 1); + sleep(1); + RedrawItem(item, 0); + DoCommand(item); + goto no_redraw; + } + } + /* goto the first text input field */ + for (i = 0; i < n_items; i++) { + item = items + i; + if (item->type == I_INPUT) { + old_item = cur_text; + old_item->input + .o_cursor = + rel_cursor; + cur_text = item; + RedrawItem(old_item, 1); + rel_cursor = + item->input + .o_cursor; + abs_cursor = + rel_cursor - + item->input.left; + goto redraw; + } + } + break; + default: + old_cursor = abs_cursor; + if ((buf[0] >= ' ' && + buf[0] < '\177') || + (buf[0] >= 160)) { /* regular or + intl char */ + if (++(cur_text->input.n) >= + cur_text->input.buf) { + cur_text->input.buf += + cur_text->input + .size; + cur_text->input.value = + (char *)realloc( + cur_text->input + .value, + cur_text->input + .buf); + } + dp = cur_text->input.value + + cur_text->input.n; + sp = dp - 1; + ep = cur_text->input.value + + rel_cursor; + for (; *dp = *sp, sp != ep; + sp--, dp--) + ; + *ep = buf[0]; + rel_cursor++; + abs_cursor++; + if (abs_cursor >= + cur_text->input.size) { + if (rel_cursor < + cur_text->input.n) + abs_cursor = + cur_text + ->input + .size - + 1; + else + abs_cursor = + cur_text + ->input + .size; + cur_text->input.left = + rel_cursor - + abs_cursor; + } + goto redraw_newcursor; + } + /* unrecognized key press, check for + * buttons */ + for (i = 0; i < n_items; i++) { + item = items + i; + fprintf(fp_err, + "Button[%d], " + "keypress==%d\n", + i, item->button.keypress); + if (item->type == I_BUTTON && + item->button.keypress == + keypress) { + RedrawItem(item, 1); + sleep( + 1); /* .5 seconds */ + RedrawItem(item, 0); + DoCommand(item); + goto no_redraw; + } + } + break; + } + redraw_newcursor: { + int x, dy; + x = BOX_SPC + TEXT_SPC + + FontWidth(xfs[f_input]) * + old_cursor - 1; + dy = cur_text->header.size_y - 1; + XSetForeground( + dpy, gc_button, colors[c_itemback]); + XDrawLine(dpy, cur_text->header.win, + gc_button, x, BOX_SPC, x, + dy - BOX_SPC); + } + redraw: { + int len, x, dy; + len = cur_text->input.n - + cur_text->input.left; + if (len > cur_text->input.size) + len = cur_text->input.size; + else + XDrawImageString(dpy, + cur_text->header.win, + gc_input, + BOX_SPC + TEXT_SPC + + FontWidth(xfs[f_input]) * + len, + BOX_SPC + TEXT_SPC + + xfs[f_input]->ascent, + cur_text->input.blanks, + cur_text->input.size - len); + XDrawImageString(dpy, + cur_text->header.win, gc_input, + BOX_SPC + TEXT_SPC, + BOX_SPC + TEXT_SPC + + xfs[f_input]->ascent, + cur_text->input.value + + cur_text->input.left, len); + x = BOX_SPC + TEXT_SPC + + FontWidth(xfs[f_input]) * + abs_cursor - 1; + dy = cur_text->header.size_y - 1; + XDrawLine(dpy, cur_text->header.win, + gc_input, x, BOX_SPC, x, + dy - BOX_SPC); + } + no_redraw: + break; /* end of case KeyPress */ + } /* end of switch (event.type) */ + continue; + } /* end of if (event.xany.window == frame) */ + for (i = 0; i < n_items; i++) { + item = items + i; + if (event.xany.window == item->header.win) { + switch (event.type) { + case Expose: + RedrawItem(item, 0); + break; + case ButtonPress: + if (item->type == I_INPUT) { + old_item = cur_text; + old_item->input.o_cursor = + rel_cursor; + cur_text = item; + RedrawItem(old_item, 1); + abs_cursor = + (event.xbutton.x - BOX_SPC - + TEXT_SPC + + FontWidth( + xfs[f_input]) / + 2) / + FontWidth(xfs[f_input]); + if (abs_cursor < 0) + abs_cursor = 0; + if (abs_cursor > + item->input.size) + abs_cursor = + item->input.size; + rel_cursor = abs_cursor + + item->input.left; + if (rel_cursor < 0) + rel_cursor = 0; + if (rel_cursor > item->input.n) + rel_cursor = + item->input.n; + if (rel_cursor > 0 && + rel_cursor == + item->input.left) + item->input.left--; + if (rel_cursor < + item->input.n && + rel_cursor == + item->input.left + + item->input.size) + item->input.left++; + abs_cursor = rel_cursor - + item->input.left; + RedrawItem(item, 0); + } + if (item->type == I_CHOICE) + ToggleChoice(item); + if (item->type == I_BUTTON) { + RedrawItem(item, 1); + XGrabPointer(dpy, + item->header.win, False, + ButtonReleaseMask, + GrabModeAsync, + GrabModeAsync, None, None, + CurrentTime); + } + break; + case ButtonRelease: + RedrawItem(item, 0); + if (grab_server && server_grabbed) { + XGrabPointer(dpy, frame, True, + 0, GrabModeAsync, + GrabModeAsync, None, None, + CurrentTime); + XFlush(dpy); + } else { + XUngrabPointer( + dpy, CurrentTime); + XFlush(dpy); + } + if (event.xbutton.x >= 0 && + event.xbutton.x < + item->header.size_x && + event.xbutton.y >= 0 && + event.xbutton.y < + item->header.size_y) { + DoCommand(item); + } + break; + } + } + } /* end of for (i = 0 */ + } /* while loop */ } /* main event loop */ -void MainLoop () +void +MainLoop() { - fd_set fds; - - while (1) { - FD_ZERO(&fds); - FD_SET(fd_in, &fds); - FD_SET(fd_x, &fds); - - XFlush(dpy); - if (select(32, &fds, NULL, NULL, NULL) > 0) { - if (FD_ISSET(fd_in, &fds)) - ReadFvwm(); - if (FD_ISSET(fd_x, &fds)) - ReadXServer(); - } - } + fd_set fds; + + while (1) { + FD_ZERO(&fds); + FD_SET(fd_in, &fds); + FD_SET(fd_x, &fds); + + XFlush(dpy); + if (select(32, &fds, NULL, NULL, NULL) > 0) { + if (FD_ISSET(fd_in, &fds)) + ReadFvwm(); + if (FD_ISSET(fd_x, &fds)) + ReadXServer(); + } + } } - /* main procedure */ -int main (int argc, char **argv) +int +main(int argc, char **argv) { - FILE *fdopen(); - int i; + int i; - buf = (char *)malloc(N); /* some kludge */ + buf = (char *)malloc(N); /* some kludge */ #ifdef DEBUG - fd_err = open(".FvwmFormErrors", O_WRONLY | O_CREAT, 0777); - fp_err = fdopen(fd_err, "w"); + fd_err = open(".FvwmFormErrors", O_WRONLY | O_CREAT, 0777); + fp_err = fdopen(fd_err, "w"); #else - fd_err = open("/dev/null", O_WRONLY); - fp_err = fdopen(fd_err, "w"); + fd_err = open("/dev/null", O_WRONLY); + fp_err = fdopen(fd_err, "w"); #endif - /* we get rid of the path from program name */ - prog_name = argv[0]; - i = strlen(prog_name); - while (prog_name[--i] != '/' && i > 0); - if (i > 0) - prog_name = prog_name + (i + 1); - fprintf(fp_err, "%s started...\n", prog_name); + /* we get rid of the path from program name */ + prog_name = argv[0]; + i = strlen(prog_name); + while (prog_name[--i] != '/' && i > 0) + ; + if (i > 0) + prog_name = prog_name + (i + 1); + fprintf(fp_err, "%s started...\n", prog_name); - if (argc < 6) { + if (argc < 6) { #ifndef DEBUG - fprintf(fp_err, "%s must be started by Fvwm.\n", prog_name); - exit(1); + fprintf(fp_err, "%s must be started by Fvwm.\n", prog_name); + exit(1); #else - fd_out = 1; - fd_in = 0; - ref = None; + fd_out = 1; + fd_in = 0; + ref = None; #endif - } else { - if(argc==7) - prog_name = argv[6]; - fd_out = atoi(argv[1]); - fd_in = atoi(argv[2]); - ref = strtol(argv[4], NULL, 16); - if (ref == 0) ref = None; + } else { + if (argc == 7) + prog_name = argv[6]; + fd_out = atoi(argv[1]); + fd_in = atoi(argv[2]); + ref = strtol(argv[4], NULL, 16); + if (ref == 0) + ref = None; #ifdef DEBUG - fprintf(fp_err, "ref == %d\n", ref); + fprintf(fp_err, "ref == %d\n", ref); #endif - } + } - fd[0]=fd_out; - fd[1]=fd_in; + fd[0] = fd_out; + fd[1] = fd_in; - if (!(dpy = XOpenDisplay(NULL))) { - fprintf(fp_err, "%s: can't open display.\n", prog_name); - exit(1); - } - fd_x = XConnectionNumber(dpy); + if (!(dpy = XOpenDisplay(NULL))) { + fprintf(fp_err, "%s: can't open display.\n", prog_name); + exit(1); + } + fd_x = XConnectionNumber(dpy); - screen = DefaultScreen(dpy); - root = RootWindow(dpy, screen); - scr_depth = DefaultDepth(dpy, screen); - d_cmap = DefaultColormap(dpy, screen); + screen = DefaultScreen(dpy); + root = RootWindow(dpy, screen); + scr_depth = DefaultDepth(dpy, screen); + d_cmap = DefaultColormap(dpy, screen); - ReadConfig(); + ReadConfig(); - GetColors(); + GetColors(); - OpenWindows(); + OpenWindows(); - MainLoop(); + MainLoop(); - return 0; + return 0; } - -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(0); + exit(0); } Index: fvwm/modules/FvwmIconBox/FvwmIconBox.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconBox/FvwmIconBox.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconBox/FvwmIconBox.1 --- fvwm/modules/FvwmIconBox/FvwmIconBox.1 +++ fvwm/modules/FvwmIconBox/FvwmIconBox.1 @@ -1,86 +1,76 @@ .\" $OpenBSD: FvwmIconBox.1,v 1.1.1.1 2006/11/26 10:53:47 matthieu Exp $ .\" t -.\" @(#)FvwmIconBox.1 6/20/94 -.TH FvwmIconBox 1 "Jun 24 1994" 0.64 +.\" @(#)FvwmIconBox.1 6/20/94 +.TH FVWMICONBOX 1 "June 24, 1994" "0.64" "FVWM Modules" .UC .SH NAME FvwmIconBox \- the FVWM iconbox module .SH SYNOPSIS FvwmIconBox is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -The FvwmIconBox module provides an icon manager. The user can do -operations, like iconify and deiconify, for each icon shown in the -module via mouse and keyboard. - -FvwmIconBox reads the same .fvwmrc file as fvwm reads when it starts up, +The FvwmIconBox module provides an icon manager. +The user can do operations, like iconify and deiconify, for each icon +shown in the module via mouse and keyboard. +.PP +FvwmIconBox reads the same .fvwmrc file as fvwm reads when it starts up and looks for lines similar to "*FvwmIconBoxFore green". - .SH COPYRIGHTS The FvwmIconBox program is original work of Nobutaka Suzuki. - -Copyright 1994, Nobutaka Suzuki. No guarantees or warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - - +.PP +Copyright 1994, Nobutaka Suzuki. +No guarantees or warranties or anything are provided or implied in any +way whatsoever. +Use this program at your own risk. +Permission to use this program for any purpose is given, as long as the +copyright is kept intact. .SH INITIALIZATION -During initialization, \fIFvwmIconBox\fP will eventually search a -configuration file. The configuration file is the same file that fvwm -used during initialization. - +During initialization, \fIFvwmIconBox\fP will eventually search a +configuration file. +The configuration file is the same file that fvwm used during +initialization. +.PP If the FvwmIconBox executable is linked to another name, ie ln -s FvwmIconBox MoreIconBox, then another module called MoreIconBox can be started, with a completely different configuration than FvwmIconBox, -simply by changing the keyword FvwmIconBox to MoreIconBox. This way -multiple clutter-reduction programs can be used. - +simply by changing the keyword FvwmIconBox to MoreIconBox. +This way multiple clutter-reduction programs can be used. .SH INVOCATION -FvwmIconBox can be invoked by binding the action 'Module -FvwmIconBox' to a menu or key-stroke in the .fvwmrc file. -Fvwm will search directory specified in the ModulePath configuration -option to attempt to locate FvwmIconBox. - +FvwmIconBox can be invoked by binding the action 'Module FvwmIconBox' +to a menu or key-stroke in the .fvwmrc file. +Fvwm will search the directory specified in the ModulePath +configuration option to attempt to locate FvwmIconBox. .SH CONFIGURATION OPTIONS -FvwmIconBox shows icons only if NoIcon is applied. Note that the -NoIcon attribute should be set after the Icon attribute specification. +FvwmIconBox shows icons only if NoIcon is applied. +Note that the NoIcon attribute should be set after the Icon attribute +specification. Otherwise the icon-box module might become nothing but an empty-box -module. The module reads the same .fvwmrc file as fvwm reads when it -starts up, and looks for lines as listed below: - +module. +The module reads the same .fvwmrc file as fvwm reads when it starts up +and looks for lines as listed below: .IP "*FvwmIconBoxFore \fIcolor\fP" Tells the module to use \fIcolor\fP instead of white for the window foreground. This option affects only the foreground color of background_bitmap specified in *FvwmIconBoxPixmap option described -below. - +below. .IP "*FvwmIconBoxBack \fIcolor\fP" Tells the module to use \fIcolor\fP instead of black for the window background. - .IP "*FvwmIconBoxIconFore \fIcolor\fP" Tells the module to use \fIcolor\fP instead of black for non-selected -icon text. - +icon text. .IP "*FvwmIconBoxIconBack \fIcolor\fP" Tells the module to use \fIcolor\fP instead of white for the non-selected icon background. - .IP "*FvwmIconBoxIconHiFore \fIcolor\fP" Tells the module to use \fIcolor\fP instead of black for selected icon -text. - +text. .IP "*FvwmIconBoxIconHiBack \fIcolor\fP" Tells the module to use \fIcolor\fP instead of white for the selected icon background. - .IP "*FvwmIconBoxPixmap \fIpixmap\fP" Tells the module to use \fIpixmap\fP for the window background_pixmap. - .IP "*FvwmIconBoxFont \fIfontname\fP" Tells the module to use \fIfontname\fP instead of fixed for text. - .IP "*FvwmIconBoxSortIcons \fIoption\fP" Tells the module to sort all icons in iconbox in alphabetical order. \fIoption\fP can be \fIWindowName\fP, \fIIconName\fP, \fIResClass\fP, @@ -88,21 +78,17 @@ and \fIResName\fP. For example, specifying \fIResClass\fP means that icons are sorted by using their resource-class strings. If \fIoption\fP is \fIResClass\fP or \fIResName\fP, an icon having no XA_WM_CLASS property is considered to be the "smallest" element. - .IP "*FvwmIconBoxPadding \fInumber\fP" Specifies the number of pixels between icons. The default value is 5. - .IP "*FvwmIconBoxSBWidth \fInumber\fP" Specifies the width of horizontal and vertical scrollbars. The default -value is 9. - +value is 9. .IP "*FvwmIconBoxPlacement \fIprimary\fP \fIsecondary\fP" Specifies icon placement policy. \fIprimary\fP and \fIsecondary\fP can -be \fITop\fP, \fIBottom\fP, \fILeft\fP and \fIRight\fP. The following -eight combinations are available: +be \fITop\fP, \fIBottom\fP, \fILeft\fP and \fIRight\fP. +The following eight combinations are available: .nf -.sp -\fIprimary\fP \fIsecondary\fP +\fIprimary\fP \fIsecondary\fP Left Top Left Bottom @@ -116,119 +102,112 @@ eight combinations are available: .fi .B "\fITop\fP:" Icons are placed from top to bottom. - .B "\fIBottom\fP:" Icons are placed from bottom to top. - .B "\fILeft\fP:" Icons are placed from left to right. - .B "\fIRight\fP:" Icons are placed from right to left. - +.PP For example, when the placement is "Left Top", icons are placed from left to right, and new rows are added from top to bottom. The default -vale is "Left Bottom". - +value is "Left Bottom". .IP "*FvwmIconBoxLines" Specifies the number of icons placed in a line. If \fIprimary\fP is -Left or Right, this value specifies the number of columns. +Left or Right, this value specifies the number of columns. If \fIprimary\fP is Top or Bottom, this value specifies the number of -rows. For example, seven icons are placed in a row if -*FvwmIconBoxLines is 7 and *FvwmIconBoxPlacement is "Left Top". -The default value is 6. - +rows. +For example, seven icons are placed in a row if *FvwmIconBoxLines is 7 +and *FvwmIconBoxPlacement is "Left Top". +The default value is 6. .IP "*FvwmIconBoxHideSC \fIdirection\fP" -Specifies the undisplayed scroll bar . \fIDirection\fP can be -either \fIHorizontal\fP or \fIVertical\fP. - +Specifies the undisplayed scroll bar. +\fIDirection\fP can be either \fIHorizontal\fP or \fIVertical\fP. .IP "*FvwmIconBoxGeometry \fIx{+-}{+-}\fP" -Specifies the location and/or size of FvwmIconBox. -\fIwidth\fP and \fIheight\fP are measured in icons, not pixels. -The default value is 6x1+0+0. - +Specifies the location and/or size of FvwmIconBox. +\fIwidth\fP and \fIheight\fP are measured in icons, not pixels. +The default value is 6x1+0+0. .IP "*FvwmIconBoxMaxIconSize \fIx\fP" Specifies the maximum size of icon bitmap. A bitmap larger than -this size is clipped to this size. The default value is 48x48. In -particular, if the height is 0, then icon bitmaps are not displayed and -only icon labels are drawn. - +this size is clipped to this size. +The default value is 48x48. +In particular, if the height is 0, then icon bitmaps are not displayed +and only icon labels are drawn. .IP "*FvwmIconBoxMouse \fIButton\fP \fIAction\fP \fIResponse[, Response]\fP" Tells the module to do \fIResponse\fP when \fIAction\fP is done on button \fIButton\fP. Available \fIResponse\fPes are built-in commands -in Fvwm (e.g. Iconify, Delete, Focus) and available \fIAction\fPs -are Click and DoubleClick. - +in Fvwm (e.g. Iconify, Delete, Focus) and available \fIAction\fPs are +Click and DoubleClick. .IP "*FvwmIconBoxKey \fIKey\fP \fIResponse[, Response]\fP" Tells the module to do \fIResponse\fP when \fIKey\fP is pressed. -Available \fIResponse\fPes are, besides Fvwm built-in commands, the -following six FvwmIconBox built-in commands: \fINext\fP, \fIPrev\fP, -\fILeft\fP, \fIRight\fP, \fIUp\fP, and \fIDown\fP. - -.B "\fINext\fP:" -Change the hilited-icon to the next. - -.B "\fIPrev\fP:" +Available \fIResponse\fPes are, besides Fvwm built-in commands, the +following six FvwmIconBox built-in commands: \fINext\fP, \fIPrev\fP, +\fILeft\fP, \fIRight\fP, \fIUp\fP, and \fIDown\fP. +.RS +.TP 8 +.B \fINext\fP +Change the hilited-icon to the next. +.TP 8 +.B \fIPrev\fP Change the hilited-icon to the previous. - -.B "\fILeft\fP:" -Move the slider of the horizontal scrollbar to left. Icons move -to right accordingly. - -.B "\fIRight\fP:" -Move the slider of the horizontal scrollbar to right. Icons move -to left accordingly. - -.B "\fIUp\fP:" -Move the slider of the vertical scrollbar to up. Icons move to -down accordingly. - -.B "\fIDown\fP:" -Move the slider of the vertical scrollbar to down. Icons move to -up accordingly. - -.IP "*FvwmIconBox \fIwindowname\fP \fIbitmap-file\fP" +.TP 8 +.B \fILeft\fP +Move the slider of the horizontal scrollbar to left. +Icons move to right accordingly. +.TP 8 +.B \fIRight\fP +Move the slider of the horizontal scrollbar to right. +Icons move to left accordingly. +.TP 8 +.B \fIUp\fP +Move the slider of the vertical scrollbar to up. +Icons move down accordingly. +.TP 8 +.B \fIDown\fP +Move the slider of the vertical scrollbar to down. +Icons move up accordingly. +.RE +.IP "*FvwmIconBox \fIwindowname\fP \fIbitmap-file\fP" Specifies the bitmap to be displayed in iconbox for \fIwindowname\fP. This option "overrides" bitmap files specified in Style command. \fIWindowname\fP can be window name, class name, or resource name. -\fIWindowname\fP can contain "*" and "?" like Fvwm configuration -file. The \fIbitmap-file\fP is either the full path name to a bitmap -file, or a file in the IconPath or PixmapPath. If \fIbitmap-file\fP is -specified to be "-", the icon for a window corresponding to -\fIwindowname\fP is not shown in the iconbox. - +\fIWindowname\fP can contain "*" and "?" like Fvwm configuration +file. +The \fIbitmap-file\fP is either the full path name to a bitmap file, or +a file in the IconPath or PixmapPath. +If \fIbitmap-file\fP is specified to be "-", the icon for a window +corresponding to \fIwindowname\fP is not shown in the iconbox. .IP "*FvwmIconBoxSetWMIconSize" -Tells the module to set XA_WM_ICON_SIZE property of the root window -at the size which the module want icon windows to have. If you show -icon windows on not the root window but the module, it would be -better to specify this option. - +Tells the module to set XA_WM_ICON_SIZE property of the root window at +the size which the module wants icon windows to have. +If you show icon windows on the module instead of the root window, it +is better to specify this option. .IP "*FvwmIconBoxHilightFocusWin" Tells the module to hilight the icon of the window which has the -keyboard focus. The fore/back colors of the hilighted icon are those -specified in the *FvwmIconBoxIconHiFore and *FvwmIconBoxIconHiBack -commands, respectively. - +keyboard focus. +The fore/back colors of the hilighted icon are those specified in the +*FvwmIconBoxIconHiFore and *FvwmIconBoxIconHiBack commands, +respectively. .IP "*FvwmIconBoxResolution \fIresolution\fP" If \fIresolution\fP is Desk, then the module shows only the icons on -the current desk. Currently, Desk is the only value \fIresolution\fP -can take :) - +the current desk. +Currently, Desk is the only value \fIresolution\fP can take :) .IP "*FvwmIconBoxFrameWidth \fIwidth1\fP \fIwidth2\fP" -Specifies the frame-width of the module. \fIWidth1\fP corresponds to -the width from the outer-border to the scroll-bar, and, \fIwidth2\fP -corresponds to the width from the scroll-bar to the internal-window -displaying icons. The default values are 8 and 6, respectively. - +Specifies the frame-width of the module. +\fIWidth1\fP corresponds to the width from the outer-border to the +scroll-bar, and \fIwidth2\fP corresponds to the width from the +scroll-bar to the internal-window displaying icons. +The default values are 8 and 6, respectively. .SH SAMPLE CONFIGURATION -The following are excepts from a .fvwmrc file which describe +The following are excerpts from a .fvwmrc file which describe FvwmIconBox initialization commands: +.PP +.RS .nf -.sp XCOMM########################################################### XCOMM Note that icons are shown in the module XCOMM only if NoIcon attribute is applied. -Style "*" NoIcon +Style "*" NoIcon XCOMM########################################################### *FvwmIconBoxIconBack #cfcfcf @@ -239,18 +218,18 @@ XCOMM*FvwmIconBoxFore blue *FvwmIconBoxGeometry 5x1+0+0 *FvwmIconBoxMaxIconSize 64x38 *FvwmIconBoxFont -adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-* -*FvwmIconBoxSortIcons IconName -XCOMM*FvwmIconBoxSortIcons ResClass +*FvwmIconBoxSortIcons IconName +XCOMM*FvwmIconBoxSortIcons ResClass *FvwmIconBoxPadding 4 *FvwmIconBoxFrameWidth 9 7 *FvwmIconBoxLines 10 *FvwmIconBoxSBWidth 11 *FvwmIconBoxPlacement Left Top *FvwmIconBoxPixmap fvwm.xpm -XCOMM*FvwmIconBoxHideSC Horizontal +XCOMM*FvwmIconBoxHideSC Horizontal *FvwmIconBoxSetWMIconSize *FvwmIconBoxHilightFocusWin -XCOMM*FvwmIconBoxResolution Desk +XCOMM*FvwmIconBoxResolution Desk XCOMM XCOMM mouse bindings XCOMM @@ -274,15 +253,13 @@ XCOMM *FvwmIconBoxKey k Up *FvwmIconBoxKey l Right XCOMM -XCOMM Icon file specifications +XCOMM Icon file specifications XCOMM -XCOMM Mostly, you don't have to specify icon files, as FvwmIconBox now -XCOMM reads icon files specified in Style commands. +XCOMM Mostly, you don't have to specify icon files, as FvwmIconBox now +XCOMM reads icon files specified in Style commands. XCOMM *FvwmIconBox "Fvwm*" - -.sp .fi - +.RE .SH AUTHOR Nobutaka Suzuki (nobuta-s@is.aist-nara.ac.jp). - Index: fvwm/modules/FvwmIconBox/FvwmIconBox.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconBox/FvwmIconBox.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconBox/FvwmIconBox.c --- fvwm/modules/FvwmIconBox/FvwmIconBox.c +++ fvwm/modules/FvwmIconBox/FvwmIconBox.c @@ -18,32 +18,32 @@ #define HORIZONTAL 2 #include "config.h" +#include "../../fvwm/fvwm_sandbox.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include -#include +#include +#include + #include +#include +#include #include -#include -#include #if HAVE_SYS_SELECT_H #include #endif -#include +#include +#include +#include +#include +#include #include #include -#include "../../fvwm/module.h" +#include -#include -#include -#include -#include -#include +#include "../../fvwm/module.h" #ifdef SHAPE #include @@ -51,8 +51,8 @@ /* just as same as wild.c */ #ifndef TRUE -#define TRUE 1 -#define FALSE 0 +#define TRUE 1 +#define FALSE 0 #endif #include "FvwmIconBox.h" @@ -61,8 +61,8 @@ char *MyName; XFontStruct *font; -Display *dpy; /* which display are we talking to */ -int x_fd,fd_width; +Display *dpy; /* which display are we talking to */ +int x_fd, fd_width; Window Root; int screen; @@ -82,9 +82,10 @@ char NoResource[] = "NoResource"; Pixel fore_pix, hilite_pix, back_pix, shadow_pix; Pixel icon_fore_pix, icon_back_pix, icon_hilite_pix, icon_shadow_pix; -Pixel act_icon_fore_pix, act_icon_back_pix, act_icon_hilite_pix, act_icon_shadow_pix; +Pixel act_icon_fore_pix, act_icon_back_pix, act_icon_hilite_pix, + act_icon_shadow_pix; -GC NormalGC,ShadowGC,ReliefGC,IconShadowGC,IconReliefGC; +GC NormalGC, ShadowGC, ReliefGC, IconShadowGC, IconReliefGC; Window main_win; Window holder_win; Window icon_win; @@ -98,18 +99,21 @@ long CurrentDesk; int Width, Height; int UWidth, UHeight; -#define MW_EVENTS (KeyPressMask| ExposureMask | StructureNotifyMask|\ - ButtonReleaseMask | ButtonPressMask ) -#define SCROLL_EVENTS (ExposureMask | StructureNotifyMask|\ - ButtonReleaseMask |ButtonPressMask | PointerMotionMask) -#define BUTTON_EVENTS (ExposureMask | StructureNotifyMask|\ - ButtonReleaseMask | ButtonPressMask |\ - LeaveWindowMask | PointerMotionMask) - -unsigned long m_mask = M_CONFIGURE_WINDOW|M_ADD_WINDOW|M_DESTROY_WINDOW| - M_END_WINDOWLIST| M_ICONIFY|M_DEICONIFY|M_ICON_NAME| - M_RES_NAME|M_RES_CLASS|M_WINDOW_NAME|M_ICON_FILE| - M_DEFAULTICON|M_CONFIG_INFO|M_END_CONFIG_INFO; +#define MW_EVENTS \ + (KeyPressMask | ExposureMask | StructureNotifyMask | \ + ButtonReleaseMask | ButtonPressMask) +#define SCROLL_EVENTS \ + (ExposureMask | StructureNotifyMask | ButtonReleaseMask | \ + ButtonPressMask | PointerMotionMask) +#define BUTTON_EVENTS \ + (ExposureMask | StructureNotifyMask | ButtonReleaseMask | \ + ButtonPressMask | LeaveWindowMask | PointerMotionMask) + +unsigned long m_mask = M_CONFIGURE_WINDOW | M_ADD_WINDOW | M_DESTROY_WINDOW | + M_END_WINDOWLIST | M_ICONIFY | M_DEICONIFY | + M_ICON_NAME | M_RES_NAME | M_RES_CLASS | M_WINDOW_NAME | + M_ICON_FILE | M_DEFAULTICON | M_CONFIG_INFO | + M_END_CONFIG_INFO; struct icon_info *Hilite; int main_width, main_height; @@ -117,11 +121,10 @@ int num_icons = 0; int num_rows = 1; int num_columns = 6; int Lines = 6; -int max_icon_width = 48,max_icon_height = 48; -int ButtonWidth,ButtonHeight; -int x= -100000,y= -100000,w= -1,h= -1,gravity = NorthWestGravity; -int icon_win_x = 0, icon_win_y = 0, icon_win_width = 100, -icon_win_height = 100; +int max_icon_width = 48, max_icon_height = 48; +int ButtonWidth, ButtonHeight; +int x = -100000, y = -100000, w = -1, h = -1, gravity = NorthWestGravity; +int icon_win_x = 0, icon_win_y = 0, icon_win_width = 100, icon_win_height = 100; int interval = 8; int motion = NONE; int primary = LEFT, secondary = BOTTOM; @@ -160,383 +163,448 @@ int ready = 0; unsigned long local_flags = 0; int sortby = UNSORT; -int save_color_limit; /* color limit from config */ +int save_color_limit; /* color limit from config */ /************************************************************************ Main Based on main() from GoodStuff: - Copyright 1993, Robert Nation. + Copyright 1993, Robert Nation. ************************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *display_name = NULL; - char *temp, *s; - XIconSize* size; - - temp = argv[0]; + char *display_name = NULL; + char *temp, *s; + XIconSize *size; - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; - MyName = safemalloc(strlen(temp)+1); - strcpy(MyName, temp); + { + size_t name_len = strlen(temp) + 1; + MyName = xmalloc(name_len); + strlcpy(MyName, temp, name_len); + } - signal (SIGPIPE, DeadPipe); + signal(SIGPIPE, DeadPipe); - if((argc != 6)&&(argc != 7)) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); + } - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - x_fd = XConnectionNumber(dpy); + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + x_fd = XConnectionNumber(dpy); - fd_width = GetFdWidth(); + fd_width = GetFdWidth(); - screen= DefaultScreen(dpy); - Root = RootWindow(dpy, screen); - if(Root == None) - { - fprintf(stderr,"%s: Screen %d is not valid ", MyName, screen); - exit(1); - } - InitPictureCMap(dpy,Root); /* store the root cmap */ - d_depth = DefaultDepth(dpy, screen); + screen = DefaultScreen(dpy); + Root = RootWindow(dpy, screen); + if (Root == None) { + fprintf(stderr, "%s: Screen %d is not valid ", MyName, screen); + exit(1); + } + InitPictureCMap(dpy, Root); /* store the root cmap */ + d_depth = DefaultDepth(dpy, screen); - XSetErrorHandler((XErrorHandler)myErrorHandler); + XSetErrorHandler((XErrorHandler)myErrorHandler); - ParseOptions(); + ParseOptions(); - SetMessageMask(fd, m_mask); + SetMessageMask(fd, m_mask); - if ((local_flags & SETWMICONSIZE) && (size = XAllocIconSize()) != NULL){ - size->max_width = size->min_width = max_icon_width + icon_relief; - size->max_height = size->min_height = max_icon_height + icon_relief; - size->width_inc = size->height_inc = 0; - XSetIconSizes(dpy, Root, size, 1); - XFree(size); - } + if ((local_flags & SETWMICONSIZE) && + (size = XAllocIconSize()) != NULL) { + size->max_width = size->min_width = + max_icon_width + icon_relief; + size->max_height = size->min_height = + max_icon_height + icon_relief; + size->width_inc = size->height_inc = 0; + XSetIconSizes(dpy, Root, size, 1); + XFree(size); + } - CreateWindow(); + CreateWindow(); - SendFvwmPipe(fd,"Send_WindowList",0); + SendFvwmPipe(fd, "Send_WindowList", 0); - Loop(); - return 0; + Loop(); + return 0; } - - /************************************************************************ Loop Based on Loop() from GoodStuff: Copyright 1993, Robert Nation. ************************************************************************/ -void Loop(void) +void +Loop(void) { - Window root; - struct icon_info *tmp, *exhilite; - int x,y,border_width,depth; - int i, hr = icon_relief/2; - XEvent Event; - int tw,th; - int diffx, diffy; - int oldw, oldh; - - while(1) - { - if(My_XNextEvent(dpy,&Event)) - { - switch(Event.type) - { - case Expose: - if(Event.xexpose.count == 0){ - if (Event.xany.window == main_win){ - RedrawWindow(); - }else{ - tmp = Head; - while(tmp != NULL){ - if (Event.xany.window == tmp->icon_pixmap_w){ - RedrawIcon(tmp, 1); - break; - }else if(Event.xany.window == tmp->IconWin){ - RedrawIcon(tmp, 2); - break; - } - tmp = tmp->next; - } - } - } - break; - - case ConfigureNotify: - XGetGeometry(dpy,main_win,&root,&x,&y, - (unsigned int *)&tw,(unsigned int *)&th, - (unsigned int *)&border_width, - (unsigned int *)&depth); - if (ready && (tw != main_width || th != main_height)){ - main_width = tw; - main_height= th; - oldw = Width; - oldh = Height; - num_columns = (tw - h_margin - interval + 1) / UWidth; - num_rows = (th - v_margin - interval + 1) / UHeight; - Width = UWidth * num_columns + interval - 1; - Height = UHeight * num_rows + interval -1; - XMoveResizeWindow(dpy, holder_win, margin1+2, - margin1+2, - tw - h_margin, th - v_margin); - if (!(local_flags & HIDE_H)) - XResizeWindow(dpy, h_scroll_bar, - Width - bar_width*2, bar_width); - if (!(local_flags & HIDE_V)) - XResizeWindow(dpy ,v_scroll_bar, - bar_width, Height - bar_width*2); - GetIconwinSize(&diffx, &diffy); - if (primary == BOTTOM || secondary == BOTTOM) - icon_win_y -= Height - oldh; - if (primary == RIGHT || secondary == RIGHT) - icon_win_x -= Width - oldw; - if (icon_win_x < 0) - icon_win_x = 0; - if (icon_win_y < 0) - icon_win_y = 0; - if (icon_win_x + Width > icon_win_width) - icon_win_x = icon_win_width - Width; - if (icon_win_y + Height > icon_win_height) - icon_win_y = icon_win_height - Height; - XMoveResizeWindow(dpy, icon_win, -icon_win_x, - -icon_win_y, icon_win_width, - icon_win_height); - AdjustIconWindows(); - XClearWindow(dpy,main_win); - RedrawWindow(); - } - break; - case KeyPress: - ExecuteKey(Event); - break; - case ButtonPress: - if (!(local_flags & HIDE_H)){ - if (Event.xbutton.window == h_scroll_bar) - motion = HORIZONTAL; - else if (Event.xbutton.window == l_button){ - Pressed = l_button; - RedrawLeftButton(ShadowGC, ReliefGC); - } - else if (Event.xbutton.window == r_button){ - Pressed = r_button; - RedrawRightButton(ShadowGC, ReliefGC); - } - } - if (!(local_flags & HIDE_V)){ - if (Event.xbutton.window == v_scroll_bar) - motion = VERTICAL; - else if (Event.xbutton.window == t_button){ - Pressed = t_button; - RedrawTopButton(ShadowGC, ReliefGC); - } - else if (Event.xbutton.window == b_button){ - Pressed = b_button; - RedrawBottomButton(ShadowGC, ReliefGC); - } - } - if ((tmp = Search(Event.xbutton.window)) != NULL) - ExecuteAction(Event.xbutton.x, Event.xbutton.y, tmp); - break; - - case ButtonRelease: - if (!(local_flags & HIDE_H)){ - if (Event.xbutton.window == h_scroll_bar && motion == - HORIZONTAL) - HScroll(Event.xbutton.x * icon_win_width / Width); - else if (Event.xbutton.window == l_button && Pressed == - l_button){ - Pressed = None; - RedrawLeftButton(ReliefGC, ShadowGC); - HScroll(icon_win_x - UWidth); - } - else if (Event.xbutton.window == r_button && Pressed == - r_button){ - Pressed = None; - RedrawRightButton(ReliefGC, ShadowGC); - HScroll(icon_win_x + UWidth); - } - } - if (!(local_flags & HIDE_V)){ - if (Event.xbutton.window == v_scroll_bar && motion - == VERTICAL) - VScroll(Event.xbutton.y * icon_win_height / Height); - else if (Event.xbutton.window == t_button && Pressed == - t_button){ - Pressed = None; - RedrawTopButton(ReliefGC, ShadowGC); - VScroll(icon_win_y - UHeight); - } - else if (Event.xbutton.window == b_button && Pressed == - b_button){ - Pressed = None; - RedrawBottomButton(ReliefGC, ShadowGC); - VScroll(icon_win_y + UHeight); - } - } - motion = NONE; - break; - - case MotionNotify: - if (motion == VERTICAL){ - VScroll(Event.xbutton.y * icon_win_height / Height); - }else if (motion == HORIZONTAL){ - HScroll(Event.xbutton.x * icon_win_width / Width); - } - break; - case EnterNotify: - if ((tmp = Search(Event.xcrossing.window)) != NULL) - if ((exhilite = Hilite) != tmp){ - Hilite = tmp; - if (exhilite != NULL) - RedrawIcon(exhilite, redraw_flag); - RedrawIcon(tmp, redraw_flag); - } - break; - - case LeaveNotify: - if ((tmp = Search(Event.xcrossing.window)) != NULL && - tmp == Hilite){ - Hilite = NULL; - RedrawIcon(tmp, redraw_flag); - } - if (!(local_flags & HIDE_H) && Event.xbutton.window == - l_button && Pressed == l_button){ - Pressed = None; - RedrawLeftButton(ReliefGC, ShadowGC); - } - else if (!(local_flags & HIDE_H) && Event.xbutton.window == - r_button && Pressed == r_button){ - Pressed = None; - RedrawRightButton(ReliefGC, ShadowGC); - } - else if (!(local_flags & HIDE_V) && Event.xbutton.window == - t_button && Pressed == t_button){ - Pressed = None; - RedrawTopButton(ReliefGC, ShadowGC); - } - else if (!(local_flags & HIDE_V) && Event.xbutton.window == - b_button && Pressed == b_button){ - Pressed = None; - RedrawBottomButton(ReliefGC, ShadowGC); - } - break; - case ClientMessage: - if ((Event.xclient.format==32) && - (Event.xclient.data.l[0]==wm_del_win)) - DeadPipe(1); - break; - case PropertyNotify: - switch (Event.xproperty.atom){ - case XA_WM_HINTS: - if (Event.xproperty.state == PropertyDelete) - break; - tmp = Head; - i=0; - while(tmp != NULL){ - if (Event.xproperty.window == tmp->id) - break; - tmp = tmp->next; - ++i; - } - if (tmp == NULL || tmp->wmhints == NULL || !(tmp->extra_flags & DEFAULTICON)) - break; - if (tmp->wmhints) - XFree (tmp->wmhints); - tmp->wmhints = XGetWMHints(dpy, tmp->id); - if (tmp->wmhints && (tmp->wmhints->flags & IconPixmapHint)){ + Window root; + struct icon_info *tmp, *exhilite; + int x, y, border_width, depth; + int i, hr = icon_relief / 2; + XEvent Event; + int tw, th; + int diffx, diffy; + int oldw, oldh; + + sandbox_x11_only("FvwmIconBox"); + + while (1) { + if (My_XNextEvent(dpy, &Event)) { + switch (Event.type) { + case Expose: + if (Event.xexpose.count == 0) { + if (Event.xany.window == main_win) { + RedrawWindow(); + } else { + tmp = Head; + while (tmp != NULL) { + if (Event.xany.window == + tmp->icon_pixmap_w) { + RedrawIcon( + tmp, 1); + break; + } else if (Event.xany.window == + tmp->IconWin) { + RedrawIcon( + tmp, 2); + break; + } + tmp = tmp->next; + } + } + } + break; + + case ConfigureNotify: + XGetGeometry(dpy, main_win, &root, &x, &y, + (unsigned int *)&tw, (unsigned int *)&th, + (unsigned int *)&border_width, + (unsigned int *)&depth); + if (ready && + (tw != main_width || th != main_height)) { + main_width = tw; + main_height = th; + oldw = Width; + oldh = Height; + num_columns = + (tw - h_margin - interval + 1) / + UWidth; + num_rows = + (th - v_margin - interval + 1) / + UHeight; + Width = + UWidth * num_columns + interval - 1; + Height = + UHeight * num_rows + interval - 1; + XMoveResizeWindow(dpy, holder_win, + margin1 + 2, margin1 + 2, + tw - h_margin, th - v_margin); + if (!(local_flags & HIDE_H)) + XResizeWindow(dpy, h_scroll_bar, + Width - bar_width * 2, + bar_width); + if (!(local_flags & HIDE_V)) + XResizeWindow(dpy, v_scroll_bar, + bar_width, + Height - bar_width * 2); + GetIconwinSize(&diffx, &diffy); + if (primary == BOTTOM || + secondary == BOTTOM) + icon_win_y -= Height - oldh; + if (primary == RIGHT || + secondary == RIGHT) + icon_win_x -= Width - oldw; + if (icon_win_x < 0) + icon_win_x = 0; + if (icon_win_y < 0) + icon_win_y = 0; + if (icon_win_x + Width > icon_win_width) + icon_win_x = + icon_win_width - Width; + if (icon_win_y + Height > + icon_win_height) + icon_win_y = + icon_win_height - Height; + XMoveResizeWindow(dpy, icon_win, + -icon_win_x, -icon_win_y, + icon_win_width, icon_win_height); + AdjustIconWindows(); + XClearWindow(dpy, main_win); + RedrawWindow(); + } + break; + case KeyPress: + ExecuteKey(Event); + break; + case ButtonPress: + if (!(local_flags & HIDE_H)) { + if (Event.xbutton.window == + h_scroll_bar) + motion = HORIZONTAL; + else if (Event.xbutton.window == + l_button) { + Pressed = l_button; + RedrawLeftButton( + ShadowGC, ReliefGC); + } else if (Event.xbutton.window == + r_button) { + Pressed = r_button; + RedrawRightButton( + ShadowGC, ReliefGC); + } + } + if (!(local_flags & HIDE_V)) { + if (Event.xbutton.window == + v_scroll_bar) + motion = VERTICAL; + else if (Event.xbutton.window == + t_button) { + Pressed = t_button; + RedrawTopButton( + ShadowGC, ReliefGC); + } else if (Event.xbutton.window == + b_button) { + Pressed = b_button; + RedrawBottomButton( + ShadowGC, ReliefGC); + } + } + if ((tmp = Search(Event.xbutton.window)) != + NULL) + ExecuteAction(Event.xbutton.x, + Event.xbutton.y, tmp); + break; + + case ButtonRelease: + if (!(local_flags & HIDE_H)) { + if (Event.xbutton.window == + h_scroll_bar && + motion == HORIZONTAL) + HScroll(Event.xbutton.x * + icon_win_width / Width); + else if (Event.xbutton.window == + l_button && + Pressed == l_button) { + Pressed = None; + RedrawLeftButton( + ReliefGC, ShadowGC); + HScroll(icon_win_x - UWidth); + } else if (Event.xbutton.window == + r_button && + Pressed == r_button) { + Pressed = None; + RedrawRightButton( + ReliefGC, ShadowGC); + HScroll(icon_win_x + UWidth); + } + } + if (!(local_flags & HIDE_V)) { + if (Event.xbutton.window == + v_scroll_bar && + motion == VERTICAL) + VScroll(Event.xbutton.y * + icon_win_height / + Height); + else if (Event.xbutton.window == + t_button && + Pressed == t_button) { + Pressed = None; + RedrawTopButton( + ReliefGC, ShadowGC); + VScroll(icon_win_y - UHeight); + } else if (Event.xbutton.window == + b_button && + Pressed == b_button) { + Pressed = None; + RedrawBottomButton( + ReliefGC, ShadowGC); + VScroll(icon_win_y + UHeight); + } + } + motion = NONE; + break; + + case MotionNotify: + if (motion == VERTICAL) { + VScroll(Event.xbutton.y * + icon_win_height / Height); + } else if (motion == HORIZONTAL) { + HScroll(Event.xbutton.x * + icon_win_width / Width); + } + break; + case EnterNotify: + if ((tmp = Search(Event.xcrossing.window)) != + NULL) + if ((exhilite = Hilite) != tmp) { + Hilite = tmp; + if (exhilite != NULL) + RedrawIcon(exhilite, + redraw_flag); + RedrawIcon(tmp, redraw_flag); + } + break; + + case LeaveNotify: + if ((tmp = Search(Event.xcrossing.window)) != + NULL && + tmp == Hilite) { + Hilite = NULL; + RedrawIcon(tmp, redraw_flag); + } + if (!(local_flags & HIDE_H) && + Event.xbutton.window == l_button && + Pressed == l_button) { + Pressed = None; + RedrawLeftButton(ReliefGC, ShadowGC); + } else if (!(local_flags & HIDE_H) && + Event.xbutton.window == r_button && + Pressed == r_button) { + Pressed = None; + RedrawRightButton(ReliefGC, ShadowGC); + } else if (!(local_flags & HIDE_V) && + Event.xbutton.window == t_button && + Pressed == t_button) { + Pressed = None; + RedrawTopButton(ReliefGC, ShadowGC); + } else if (!(local_flags & HIDE_V) && + Event.xbutton.window == b_button && + Pressed == b_button) { + Pressed = None; + RedrawBottomButton(ReliefGC, ShadowGC); + } + break; + case ClientMessage: + if ((Event.xclient.format == 32) && + (Event.xclient.data.l[0] == wm_del_win)) + DeadPipe(1); + break; + case PropertyNotify: + switch (Event.xproperty.atom) { + case XA_WM_HINTS: + if (Event.xproperty.state == + PropertyDelete) + break; + tmp = Head; + i = 0; + while (tmp != NULL) { + if (Event.xproperty.window == + tmp->id) + break; + tmp = tmp->next; + ++i; + } + if (tmp == NULL || + tmp->wmhints == NULL || + !(tmp->extra_flags & DEFAULTICON)) + break; + if (tmp->wmhints) + XFree(tmp->wmhints); + tmp->wmhints = + XGetWMHints(dpy, tmp->id); + if (tmp->wmhints && + (tmp->wmhints->flags & + IconPixmapHint)) { #ifdef SHAPE - /* turn off "old" shape mask */ - if (tmp->icon_maskPixmap != None) - XShapeCombineMask(dpy, tmp->icon_pixmap_w, - ShapeBounding, 0, 0, None, ShapeSet); + /* turn off "old" shape mask */ + if (tmp->icon_maskPixmap != + None) + XShapeCombineMask(dpy, + tmp->icon_pixmap_w, + ShapeBounding, 0, 0, + None, ShapeSet); #endif - if (tmp->iconPixmap != None) - XFreePixmap(dpy, tmp->iconPixmap); - GetIconBitmap(tmp); + if (tmp->iconPixmap != None) + XFreePixmap(dpy, + tmp->iconPixmap); + GetIconBitmap(tmp); #ifdef SHAPE - if (tmp->icon_maskPixmap != None) - XShapeCombineMask(dpy, tmp->icon_pixmap_w, - ShapeBounding, hr, hr, - tmp->icon_maskPixmap, ShapeSet); + if (tmp->icon_maskPixmap != + None) + XShapeCombineMask(dpy, + tmp->icon_pixmap_w, + ShapeBounding, hr, + hr, + tmp->icon_maskPixmap, + ShapeSet); #endif - AdjustIconWindow(tmp, i); - if (max_icon_height != 0) - RedrawIcon(tmp, 1); + AdjustIconWindow(tmp, i); + if (max_icon_height != 0) + RedrawIcon(tmp, 1); + } + break; + } + break; + + default: + break; + } } - break; - } - break; - - default: - break; - } } - } - return; + return; } -void HScroll(int x) +void +HScroll(int x) { - int oldx = icon_win_x; - - if (x + Width > icon_win_width) - x = icon_win_width - Width; - if (x < 0) - x = 0; - if (oldx != x){ - icon_win_x = x; - XMoveWindow(dpy,icon_win, -icon_win_x, -icon_win_y); - if (!(local_flags & HIDE_H)) - RedrawHScrollbar(); - } + int oldx = icon_win_x; + + if (x + Width > icon_win_width) + x = icon_win_width - Width; + if (x < 0) + x = 0; + if (oldx != x) { + icon_win_x = x; + XMoveWindow(dpy, icon_win, -icon_win_x, -icon_win_y); + if (!(local_flags & HIDE_H)) + RedrawHScrollbar(); + } } -void VScroll(int y) +void +VScroll(int y) { - int oldy = icon_win_y; - - if (y + Height > icon_win_height) - y = icon_win_height - Height; - if (y < 0) - y = 0; - if (oldy != y){ - icon_win_y = y; - XMoveWindow(dpy,icon_win, -icon_win_x, -icon_win_y); - if (!(local_flags & HIDE_V)) - RedrawVScrollbar(); - } + int oldy = icon_win_y; + + if (y + Height > icon_win_height) + y = icon_win_height - Height; + if (y < 0) + y = 0; + if (oldy != y) { + icon_win_y = y; + XMoveWindow(dpy, icon_win, -icon_win_x, -icon_win_y); + if (!(local_flags & HIDE_V)) + RedrawVScrollbar(); + } } -struct icon_info *Search(Window w) +struct icon_info * +Search(Window w) { - struct icon_info *tmp; + struct icon_info *tmp; - tmp = Head; - while (tmp != NULL){ - if (tmp->IconWin == w || tmp->icon_pixmap_w == w) - return tmp; - tmp = tmp->next; - } - return NULL; + tmp = Head; + while (tmp != NULL) { + if (tmp->IconWin == w || tmp->icon_pixmap_w == w) + return tmp; + tmp = tmp->next; + } + return NULL; } /************************************************************************ @@ -544,151 +612,156 @@ struct icon_info *Search(Window w) * Draw the window * ***********************************************************************/ -void RedrawWindow(void) +void +RedrawWindow(void) { - XEvent dummy; - - while (XCheckTypedWindowEvent (dpy, main_win, Expose, &dummy)); - - RelieveWindow(main_win, margin1, margin1, Width + 4, - Height + 4, ShadowGC,ReliefGC); - if (!(local_flags & HIDE_H)) - RelieveWindow(main_win, margin1, margin1 + 4 + Height + margin2, - Width + 4, bar_width+4, ShadowGC,ReliefGC); - if (!(local_flags & HIDE_V)) - RelieveWindow(main_win, margin1 + 4 + Width + margin2, margin1, - bar_width+4, Height + 4, ShadowGC,ReliefGC); - RelieveWindow(main_win, 0, 0, Width + h_margin, Height + v_margin, - ReliefGC, ShadowGC); - - /* scroll bar */ - if (!(local_flags & HIDE_H)) - RedrawHScrollbar(); - if (!(local_flags & HIDE_V)) - RedrawVScrollbar(); - - /* buttons */ - if (!(local_flags & HIDE_H)){ - RedrawLeftButton(ReliefGC, ShadowGC); - RedrawRightButton(ReliefGC, ShadowGC); - } - if (!(local_flags & HIDE_V)){ - RedrawTopButton(ReliefGC, ShadowGC); - RedrawBottomButton(ReliefGC, ShadowGC); - } + XEvent dummy; - /* icons */ - RedrawIcons(); + while (XCheckTypedWindowEvent(dpy, main_win, Expose, &dummy)) + ; + + RelieveWindow(main_win, margin1, margin1, Width + 4, Height + 4, + ShadowGC, ReliefGC); + if (!(local_flags & HIDE_H)) + RelieveWindow(main_win, margin1, margin1 + 4 + Height + margin2, + Width + 4, bar_width + 4, ShadowGC, ReliefGC); + if (!(local_flags & HIDE_V)) + RelieveWindow(main_win, margin1 + 4 + Width + margin2, margin1, + bar_width + 4, Height + 4, ShadowGC, ReliefGC); + RelieveWindow(main_win, 0, 0, Width + h_margin, Height + v_margin, + ReliefGC, ShadowGC); + + /* scroll bar */ + if (!(local_flags & HIDE_H)) + RedrawHScrollbar(); + if (!(local_flags & HIDE_V)) + RedrawVScrollbar(); + + /* buttons */ + if (!(local_flags & HIDE_H)) { + RedrawLeftButton(ReliefGC, ShadowGC); + RedrawRightButton(ReliefGC, ShadowGC); + } + if (!(local_flags & HIDE_V)) { + RedrawTopButton(ReliefGC, ShadowGC); + RedrawBottomButton(ReliefGC, ShadowGC); + } + + /* icons */ + RedrawIcons(); } -void RedrawIcons(void) +void +RedrawIcons(void) { - struct icon_info *tmp; + struct icon_info *tmp; - tmp = Head; - while(tmp != NULL){ - if (desk_cond(tmp)) - RedrawIcon(tmp, redraw_flag); - tmp = tmp->next; - } + tmp = Head; + while (tmp != NULL) { + if (desk_cond(tmp)) + RedrawIcon(tmp, redraw_flag); + tmp = tmp->next; + } } -void RedrawIcon(struct icon_info *item, int f) +void +RedrawIcon(struct icon_info *item, int f) { - unsigned long plane = 1; - int hr, len; - int diff, lm ,w, h, tw; - char label[256]; - - hr = icon_relief/2; - - if (Hilite == item){ - XSetForeground(dpy, NormalGC, act_icon_fore_pix); - XSetBackground(dpy, NormalGC, act_icon_back_pix); - XSetForeground(dpy, IconReliefGC, act_icon_hilite_pix); - XSetForeground(dpy, IconShadowGC, act_icon_shadow_pix); - - if (max_icon_height != 0 && (item->flags & ICON_OURS)) - XSetWindowBackground(dpy, item->icon_pixmap_w, act_icon_back_pix); - XSetWindowBackground(dpy, item->IconWin, act_icon_back_pix); - } + unsigned long plane = 1; + int hr, len; + int diff, lm, w, h, tw; + char label[256]; + + hr = icon_relief / 2; + + if (Hilite == item) { + XSetForeground(dpy, NormalGC, act_icon_fore_pix); + XSetBackground(dpy, NormalGC, act_icon_back_pix); + XSetForeground(dpy, IconReliefGC, act_icon_hilite_pix); + XSetForeground(dpy, IconShadowGC, act_icon_shadow_pix); + + if (max_icon_height != 0 && (item->flags & ICON_OURS)) + XSetWindowBackground( + dpy, item->icon_pixmap_w, act_icon_back_pix); + XSetWindowBackground(dpy, item->IconWin, act_icon_back_pix); + } - /* icon pixmap */ - if ((f & 1) && (item->flags & ICON_OURS)){ - if (item->iconPixmap != None && item->icon_pixmap_w != None){ - if (item->icon_depth != d_depth) - XCopyPlane(dpy, item->iconPixmap, item->icon_pixmap_w, NormalGC, - 0, 0, item->icon_w, item->icon_h, - hr, hr, plane); - else - XCopyArea(dpy, item->iconPixmap, item->icon_pixmap_w, NormalGC, - 0, 0, item->icon_w, item->icon_h, hr, hr); - } - if (!(item->flags & SHAPED_ICON)){ - if (item->icon_w > 0 && item->icon_h > 0) - RelieveWindow(item->icon_pixmap_w, 0, 0, item->icon_w - +icon_relief, - item->icon_h + icon_relief, IconReliefGC, - IconShadowGC); - else - RelieveWindow(item->icon_pixmap_w, 0, 0, max_icon_width - +icon_relief, - max_icon_height + icon_relief, IconReliefGC, - IconShadowGC); - } - } + /* icon pixmap */ + if ((f & 1) && (item->flags & ICON_OURS)) { + if (item->iconPixmap != None && item->icon_pixmap_w != None) { + if (item->icon_depth != d_depth) + XCopyPlane(dpy, item->iconPixmap, + item->icon_pixmap_w, NormalGC, 0, 0, + item->icon_w, item->icon_h, hr, hr, plane); + else + XCopyArea(dpy, item->iconPixmap, + item->icon_pixmap_w, NormalGC, 0, 0, + item->icon_w, item->icon_h, hr, hr); + } + if (!(item->flags & SHAPED_ICON)) { + if (item->icon_w > 0 && item->icon_h > 0) + RelieveWindow(item->icon_pixmap_w, 0, 0, + item->icon_w + icon_relief, + item->icon_h + icon_relief, IconReliefGC, + IconShadowGC); + else + RelieveWindow(item->icon_pixmap_w, 0, 0, + max_icon_width + icon_relief, + max_icon_height + icon_relief, IconReliefGC, + IconShadowGC); + } + } - /* label */ - if (f & 2){ - w = max_icon_width + icon_relief; - h = max_icon_height + icon_relief; - - if (item->flags & ICONIFIED){ - sprintf(label, "(%s)", item->name); - }else - strcpy(label, item->name); - - len = strlen(label); - tw = XTextWidth(font, label, len); - diff = max_icon_width + icon_relief - tw; - lm = diff/2; - lm = lm > 4 ? lm : 4; - - if (Hilite == item){ - XRaiseWindow(dpy, item->IconWin); - XMoveResizeWindow(dpy, item->IconWin, - item->x + min(0, (diff - 8))/2, - item->y + h, - max(tw + 8, w), 6 + font->ascent + - font->descent); - XClearWindow(dpy, item->IconWin); - XDrawString(dpy, item->IconWin, NormalGC, lm, 3 + font->ascent, - label, len); - RelieveWindow(item->IconWin, 0, 0, - max(tw + 8, w), 6 + font->ascent + - font->descent, IconReliefGC, IconShadowGC); - }else{ - XMoveResizeWindow(dpy, item->IconWin, item->x, item->y + h, - w, 6 + font->ascent + font->descent); - XClearWindow(dpy, item->IconWin); - XDrawString(dpy, item->IconWin, NormalGC, lm, 3 + font->ascent, - label, len); - RelieveWindow(item->IconWin, 0, 0, - w, 6 + font->ascent + font->descent, - IconReliefGC, IconShadowGC); - } - } + /* label */ + if (f & 2) { + w = max_icon_width + icon_relief; + h = max_icon_height + icon_relief; + + if (item->flags & ICONIFIED) { + snprintf(label, sizeof(label), "(%s)", item->name); + } else + strlcpy(label, item->name, sizeof(label)); + + len = strlen(label); + tw = XTextWidth(font, label, len); + diff = max_icon_width + icon_relief - tw; + lm = diff / 2; + lm = lm > 4 ? lm : 4; + + if (Hilite == item) { + XRaiseWindow(dpy, item->IconWin); + XMoveResizeWindow(dpy, item->IconWin, + item->x + min(0, (diff - 8)) / 2, item->y + h, + max(tw + 8, w), 6 + font->ascent + font->descent); + XClearWindow(dpy, item->IconWin); + XDrawString(dpy, item->IconWin, NormalGC, lm, + 3 + font->ascent, label, len); + RelieveWindow(item->IconWin, 0, 0, max(tw + 8, w), + 6 + font->ascent + font->descent, IconReliefGC, + IconShadowGC); + } else { + XMoveResizeWindow(dpy, item->IconWin, item->x, + item->y + h, w, 6 + font->ascent + font->descent); + XClearWindow(dpy, item->IconWin); + XDrawString(dpy, item->IconWin, NormalGC, lm, + 3 + font->ascent, label, len); + RelieveWindow(item->IconWin, 0, 0, w, + 6 + font->ascent + font->descent, IconReliefGC, + IconShadowGC); + } + } - if (Hilite == item){ - XSetForeground(dpy, NormalGC, icon_fore_pix); - XSetBackground(dpy, NormalGC, icon_back_pix); - XSetForeground(dpy, IconReliefGC, icon_hilite_pix); - XSetForeground(dpy, IconShadowGC, icon_shadow_pix); + if (Hilite == item) { + XSetForeground(dpy, NormalGC, icon_fore_pix); + XSetBackground(dpy, NormalGC, icon_back_pix); + XSetForeground(dpy, IconReliefGC, icon_hilite_pix); + XSetForeground(dpy, IconShadowGC, icon_shadow_pix); - if (max_icon_height != 0 && (item->flags & ICON_OURS)) - XSetWindowBackground(dpy, item->icon_pixmap_w, icon_back_pix); - XSetWindowBackground(dpy, item->IconWin, icon_back_pix); - } + if (max_icon_height != 0 && (item->flags & ICON_OURS)) + XSetWindowBackground( + dpy, item->icon_pixmap_w, icon_back_pix); + XSetWindowBackground(dpy, item->IconWin, icon_back_pix); + } } /*********************************************************************** @@ -696,14 +769,15 @@ void RedrawIcon(struct icon_info *item, int f) * Based on part of Loop() of GrabWindow.c in FvwmScroll: * Copyright 1994, Robert Nation. ***********************************************************************/ -void RedrawHScrollbar(void) +void +RedrawHScrollbar(void) { - int x,width; + int x, width; - x = (Width - bar_width*2) * icon_win_x / icon_win_width; - width = (Width - bar_width*2) * Width / icon_win_width; - XClearArea(dpy, h_scroll_bar, 0, 0, Width, bar_width,False); - RelieveWindow(h_scroll_bar, x, 0, width, bar_width, ReliefGC, ShadowGC); + x = (Width - bar_width * 2) * icon_win_x / icon_win_width; + width = (Width - bar_width * 2) * Width / icon_win_width; + XClearArea(dpy, h_scroll_bar, 0, 0, Width, bar_width, False); + RelieveWindow(h_scroll_bar, x, 0, width, bar_width, ReliefGC, ShadowGC); } /*********************************************************************** @@ -711,123 +785,177 @@ void RedrawHScrollbar(void) * Based on part of Loop() of GrabWindow.c in FvwmScroll: * Copyright 1994, Robert Nation. ***********************************************************************/ -void RedrawVScrollbar(void) +void +RedrawVScrollbar(void) { - int y, height; + int y, height; - y = (Height - bar_width*2) * icon_win_y / icon_win_height; - height = (Height - bar_width*2)* Height / icon_win_height; - XClearArea(dpy, v_scroll_bar, 0, 0, bar_width, Height,False); - RelieveWindow(v_scroll_bar, 0, y, bar_width, height, ReliefGC, ShadowGC); + y = (Height - bar_width * 2) * icon_win_y / icon_win_height; + height = (Height - bar_width * 2) * Height / icon_win_height; + XClearArea(dpy, v_scroll_bar, 0, 0, bar_width, Height, False); + RelieveWindow( + v_scroll_bar, 0, y, bar_width, height, ReliefGC, ShadowGC); } -void RedrawLeftButton(GC rgc, GC sgc) +void +RedrawLeftButton(GC rgc, GC sgc) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = 1; seg[i].y1 = bar_width/2; - seg[i].x2 = bar_width - 2; seg[i++].y2 = 1; - - seg[i].x1 = 0; seg[i].y1 = bar_width/2; - seg[i].x2 = bar_width - 1; seg[i++].y2 = 0; - XDrawSegments(dpy, l_button, rgc, seg, i); - - i = 0; - seg[i].x1 = 1; seg[i].y1 = bar_width/2; - seg[i].x2 = bar_width - 2; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = 0; seg[i].y1 = bar_width/2; - seg[i].x2 = bar_width - 1; seg[i++].y2 = bar_width - 1; - - seg[i].x1 = bar_width - 2; seg[i].y1 = 1; - seg[i].x2 = bar_width - 2; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = bar_width - 1; seg[i].y1 = 0; - seg[i].x2 = bar_width - 1; seg[i++].y2 = bar_width - 1; - XDrawSegments(dpy, l_button, sgc, seg, i); + XSegment seg[4]; + int i = 0; + + seg[i].x1 = 1; + seg[i].y1 = bar_width / 2; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = 1; + + seg[i].x1 = 0; + seg[i].y1 = bar_width / 2; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = 0; + XDrawSegments(dpy, l_button, rgc, seg, i); + + i = 0; + seg[i].x1 = 1; + seg[i].y1 = bar_width / 2; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = 0; + seg[i].y1 = bar_width / 2; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = bar_width - 1; + + seg[i].x1 = bar_width - 2; + seg[i].y1 = 1; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = bar_width - 1; + seg[i].y1 = 0; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = bar_width - 1; + XDrawSegments(dpy, l_button, sgc, seg, i); } -void RedrawRightButton(GC rgc, GC sgc) +void +RedrawRightButton(GC rgc, GC sgc) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = 1; seg[i].y1 = 1; - seg[i].x2 = 1; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = 0; seg[i].y1 = 0; - seg[i].x2 = 0; seg[i++].y2 = bar_width - 1; - - seg[i].x1 = 1; seg[i].y1 = 1; - seg[i].x2 = bar_width - 2; seg[i++].y2 = bar_width/2; - - seg[i].x1 = 0; seg[i].y1 = 0; - seg[i].x2 = bar_width - 1; seg[i++].y2 = bar_width/2; - - XDrawSegments(dpy, r_button, rgc, seg, i); - - i = 0; - seg[i].x1 = 1; seg[i].y1 = bar_width - 2; - seg[i].x2 = bar_width - 2; seg[i++].y2 = bar_width/2; - - seg[i].x1 = 0; seg[i].y1 = bar_width - 1; - seg[i].x2 = bar_width - 1; seg[i++].y2 = bar_width/2; - XDrawSegments(dpy, r_button, sgc, seg, i); + XSegment seg[4]; + int i = 0; + + seg[i].x1 = 1; + seg[i].y1 = 1; + seg[i].x2 = 1; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = 0; + seg[i].y1 = 0; + seg[i].x2 = 0; + seg[i++].y2 = bar_width - 1; + + seg[i].x1 = 1; + seg[i].y1 = 1; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = bar_width / 2; + + seg[i].x1 = 0; + seg[i].y1 = 0; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = bar_width / 2; + + XDrawSegments(dpy, r_button, rgc, seg, i); + + i = 0; + seg[i].x1 = 1; + seg[i].y1 = bar_width - 2; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = bar_width / 2; + + seg[i].x1 = 0; + seg[i].y1 = bar_width - 1; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = bar_width / 2; + XDrawSegments(dpy, r_button, sgc, seg, i); } -void RedrawTopButton(GC rgc, GC sgc) +void +RedrawTopButton(GC rgc, GC sgc) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = bar_width/2; seg[i].y1 = 1; - seg[i].x2 = 1; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = bar_width/2; seg[i].y1 = 0; - seg[i].x2 = 0; seg[i++].y2 = bar_width - 1; - XDrawSegments(dpy, t_button, rgc, seg, i); - - i = 0; - seg[i].x1 = bar_width/2; seg[i].y1 = 1; - seg[i].x2 = bar_width - 2; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = bar_width/2; seg[i].y1 = 0; - seg[i].x2 = bar_width - 1; seg[i++].y2 = bar_width - 1; - - seg[i].x1 = 1; seg[i].y1 = bar_width - 2; - seg[i].x2 = bar_width - 2; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = 0; seg[i].y1 = bar_width - 1; - seg[i].x2 = bar_width - 1; seg[i++].y2 = bar_width - 1; - XDrawSegments(dpy, t_button, sgc, seg, i); + XSegment seg[4]; + int i = 0; + + seg[i].x1 = bar_width / 2; + seg[i].y1 = 1; + seg[i].x2 = 1; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = bar_width / 2; + seg[i].y1 = 0; + seg[i].x2 = 0; + seg[i++].y2 = bar_width - 1; + XDrawSegments(dpy, t_button, rgc, seg, i); + + i = 0; + seg[i].x1 = bar_width / 2; + seg[i].y1 = 1; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = bar_width / 2; + seg[i].y1 = 0; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = bar_width - 1; + + seg[i].x1 = 1; + seg[i].y1 = bar_width - 2; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = 0; + seg[i].y1 = bar_width - 1; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = bar_width - 1; + XDrawSegments(dpy, t_button, sgc, seg, i); } -void RedrawBottomButton(GC rgc, GC sgc) +void +RedrawBottomButton(GC rgc, GC sgc) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = 1; seg[i].y1 = 1; - seg[i].x2 = bar_width/2; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = 0; seg[i].y1 = 0; - seg[i].x2 = bar_width/2; seg[i++].y2 = bar_width - 1; - - seg[i].x1 = 1; seg[i].y1 = 1; - seg[i].x2 = bar_width - 2; seg[i++].y2 = 1; - - seg[i].x1 = 0; seg[i].y1 = 0; - seg[i].x2 = bar_width - 1; seg[i++].y2 = 0; - XDrawSegments(dpy, b_button, rgc, seg, i); - - i = 0; - seg[i].x1 = bar_width - 2; seg[i].y1 = 1; - seg[i].x2 = bar_width/2; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = bar_width - 1; seg[i].y1 = 0; - seg[i].x2 = bar_width/2; seg[i++].y2 = bar_width - 1; - XDrawSegments(dpy, b_button, sgc, seg, i); + XSegment seg[4]; + int i = 0; + + seg[i].x1 = 1; + seg[i].y1 = 1; + seg[i].x2 = bar_width / 2; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = 0; + seg[i].y1 = 0; + seg[i].x2 = bar_width / 2; + seg[i++].y2 = bar_width - 1; + + seg[i].x1 = 1; + seg[i].y1 = 1; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = 1; + + seg[i].x1 = 0; + seg[i].y1 = 0; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = 0; + XDrawSegments(dpy, b_button, rgc, seg, i); + + i = 0; + seg[i].x1 = bar_width - 2; + seg[i].y1 = 1; + seg[i].x2 = bar_width / 2; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = bar_width - 1; + seg[i].y1 = 0; + seg[i].x2 = bar_width / 2; + seg[i++].y2 = bar_width - 1; + XDrawSegments(dpy, b_button, sgc, seg, i); } /************************************************************************ @@ -835,44 +963,61 @@ void RedrawBottomButton(GC rgc, GC sgc) Original work from GoodStuff: Copyright 1993, Robert Nation. ************************************************************************/ -void RelieveWindow(Window win,int x,int y,int w,int h, GC rgc,GC sgc) +void +RelieveWindow(Window win, int x, int y, int w, int h, GC rgc, GC sgc) { - XSegment seg[4]; - int i; - - 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; - - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+1; - - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+1; seg[i++].y2 = y+h-2; - XDrawSegments(dpy, win, rgc, 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; - - seg[i].x1 = x+w-1; seg[i].y1 = y; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - if(d_depth<2) - XDrawSegments(dpy, win, ShadowGC, seg, i); - else - XDrawSegments(dpy, win, sgc, seg, i); - - i=0; - 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-2; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; - - XDrawSegments(dpy, win, sgc, seg, i); + XSegment seg[4]; + int i; + + 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; + + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + 1; + + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + 1; + seg[i++].y2 = y + h - 2; + XDrawSegments(dpy, win, rgc, 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; + + seg[i].x1 = x + w - 1; + seg[i].y1 = y; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + if (d_depth < 2) + XDrawSegments(dpy, win, ShadowGC, seg, i); + else + XDrawSegments(dpy, win, sgc, seg, i); + + i = 0; + 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 - 2; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + + XDrawSegments(dpy, win, sgc, seg, i); } /************************************************************************ @@ -880,257 +1025,236 @@ void RelieveWindow(Window win,int x,int y,int w,int h, GC rgc,GC sgc) * Based on CreateWindow() from GoodStuff: * Copyright 1993, Robert Nation. ***********************************************************************/ -void CreateWindow(void) +void +CreateWindow(void) { - XGCValues gcv; - unsigned long gcm; - unsigned long mask; - char *list[2]; - XSetWindowAttributes attributes; - XSizeHints mysizehints; - XTextProperty name; - XClassHint class_hints; - - h_margin = margin1*2 + bar_width + margin2 + 8; - v_margin = margin1*2 + bar_width + margin2 + 8; - - wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); - _XA_WM_PROTOCOLS = XInternAtom (dpy, "WM_PROTOCOLS", False); - - /* load the font */ - if ((font = XLoadQueryFont(dpy, font_string)) == NULL) - { - if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) - { - fprintf(stderr,"%s: No fonts available\n",MyName); - exit(1); - } - }; - - if ((local_flags & HIDE_H)) - v_margin -= bar_width + margin2 + 4; - if ((local_flags & HIDE_V)) - h_margin -= bar_width + margin2 + 4; - - UWidth = max_icon_width + icon_relief + interval; - UHeight = font->ascent + font->descent + max_icon_height + - icon_relief + 6 + interval; - Width = UWidth * num_columns + interval -1; - Height = UHeight * num_rows + interval -1; - - mysizehints.flags = PWinGravity| PResizeInc | PMinSize; - - /* subtract one for the right/bottom border */ - mysizehints.min_width = UWidth + interval - 1 + h_margin; - main_width = mysizehints.width = Width + h_margin; - mysizehints.min_height = UHeight + interval - 1 + v_margin; - main_height = mysizehints.height = Height + v_margin; - mysizehints.width_inc = UWidth; - mysizehints.height_inc = UHeight; - - if(x > -100000) - { - if (xneg) - { - mysizehints.x = DisplayWidth(dpy,screen) + x - mysizehints.width; - gravity = NorthEastGravity; + XGCValues gcv; + unsigned long gcm; + unsigned long mask; + char *list[2]; + XSetWindowAttributes attributes; + XSizeHints mysizehints; + XTextProperty name; + XClassHint class_hints; + + h_margin = margin1 * 2 + bar_width + margin2 + 8; + v_margin = margin1 * 2 + bar_width + margin2 + 8; + + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + _XA_WM_PROTOCOLS = XInternAtom(dpy, "WM_PROTOCOLS", False); + + /* load the font */ + if ((font = XLoadQueryFont(dpy, font_string)) == NULL) { + if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) { + fprintf(stderr, "%s: No fonts available\n", MyName); + exit(1); + } } - else - mysizehints.x = x; - if (yneg) - { - mysizehints.y = DisplayHeight(dpy,screen) + y - mysizehints.height; - gravity = SouthWestGravity; - } - else - mysizehints.y = y; - - if((xneg) && (yneg)) - gravity = SouthEastGravity; - - mysizehints.flags |= USPosition; - } - - mysizehints.win_gravity = gravity; - - if(d_depth < 2) - { - back_pix = icon_back_pix = act_icon_fore_pix = GetColor("white"); - fore_pix = icon_fore_pix = act_icon_back_pix = GetColor("black"); - hilite_pix = icon_hilite_pix = act_icon_shadow_pix = icon_back_pix; - shadow_pix = icon_shadow_pix = act_icon_hilite_pix = icon_fore_pix; - } - else - { - fore_pix = GetColor(Fore); - back_pix = GetColor(Back); - icon_back_pix = GetColor(IconBack); - icon_fore_pix = GetColor(IconFore); - icon_hilite_pix = GetHilite(icon_back_pix); - icon_shadow_pix = GetShadow(icon_back_pix); - act_icon_back_pix = GetColor(ActIconBack); - act_icon_fore_pix = GetColor(ActIconFore); - act_icon_hilite_pix = GetHilite(act_icon_back_pix); - act_icon_shadow_pix = GetShadow(act_icon_back_pix); - hilite_pix = GetHilite(back_pix); - shadow_pix = GetShadow(back_pix); - } - - main_win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y, - mysizehints.width,mysizehints.height, - 0,fore_pix,back_pix); - XSetWMProtocols(dpy,main_win,&wm_del_win,1); - XSelectInput(dpy,main_win,MW_EVENTS); - - /* set normal_hits, wm_hints, and, class_hints */ - list[0]=MyName; - list[1]=NULL; - if (XStringListToTextProperty(list,1,&name) == 0) - { - fprintf(stderr,"%s: cannot allocate window name",MyName); - return; - } - class_hints.res_name = MyName; - class_hints.res_class = "FvwmIconBox"; - XSetWMProperties(dpy,main_win,&name,&name, - NULL,0,&mysizehints,NULL,&class_hints); - XFree(name.value); - - mysizehints.width -= h_margin; - mysizehints.height -= v_margin; - holder_win = XCreateSimpleWindow(dpy,main_win,margin1+2, - margin1+2, - mysizehints.width, - mysizehints.height, - 0,fore_pix,back_pix); - - icon_win = XCreateSimpleWindow(dpy,holder_win,-icon_win_x,-icon_win_y, - icon_win_width, - icon_win_height, - 0,fore_pix,back_pix); - - gcm = GCForeground|GCBackground; - gcv.foreground = hilite_pix; - gcv.background = back_pix; - ReliefGC = XCreateGC(dpy, Root, gcm, &gcv); - - gcm = GCForeground|GCBackground; - gcv.foreground = shadow_pix; - gcv.background = back_pix; - ShadowGC = XCreateGC(dpy, Root, gcm, &gcv); - - gcm = GCForeground|GCBackground; - gcv.foreground = icon_hilite_pix; - gcv.background = icon_back_pix; - IconReliefGC = XCreateGC(dpy, Root, gcm, &gcv); - - gcm = GCForeground|GCBackground; - gcv.foreground = icon_shadow_pix; - gcv.background = icon_back_pix; - IconShadowGC = XCreateGC(dpy, Root, gcm, &gcv); - - gcm = GCForeground|GCBackground|GCFont; - gcv.foreground = fore_pix; - gcv.background = back_pix; - gcv.font = font->fid; - NormalGC = XCreateGC(dpy, Root, gcm, &gcv); - - - /* icon_win's background */ - if (GetBackPixmap() == True){ - XSetWindowBackgroundPixmap(dpy, icon_win, IconwinPixmap); - /* special thanks to Dave Goldberg - for his helpful information */ - XFreePixmap(dpy, IconwinPixmap); - } - XSetForeground(dpy, NormalGC, icon_fore_pix); - XSetBackground(dpy, NormalGC, icon_back_pix); - - /* scroll bars */ - mask = CWWinGravity | CWBackPixel; - attributes.background_pixel = back_pix; - if (!(local_flags & HIDE_H)){ - attributes.win_gravity = SouthWestGravity; - h_scroll_bar = XCreateWindow(dpy ,main_win, margin1 + 2 + - bar_width, - margin1 + 6 + Height + margin2, - Width - bar_width*2, bar_width, - 0, CopyFromParent, - InputOutput, CopyFromParent, - mask, &attributes); - XSelectInput(dpy,h_scroll_bar,SCROLL_EVENTS); - } - if (!(local_flags & HIDE_V)){ - attributes.win_gravity = NorthEastGravity; - v_scroll_bar = XCreateWindow(dpy ,main_win, margin1 + 6 + - Width + margin2, - margin1 + 2 + bar_width, - bar_width, Height - bar_width*2, - 0, CopyFromParent, - InputOutput, CopyFromParent, - mask, &attributes); - XSelectInput(dpy,v_scroll_bar,SCROLL_EVENTS); - } + if ((local_flags & HIDE_H)) + v_margin -= bar_width + margin2 + 4; + if ((local_flags & HIDE_V)) + h_margin -= bar_width + margin2 + 4; + + UWidth = max_icon_width + icon_relief + interval; + UHeight = font->ascent + font->descent + max_icon_height + icon_relief + + 6 + interval; + Width = UWidth * num_columns + interval - 1; + Height = UHeight * num_rows + interval - 1; + + mysizehints.flags = PWinGravity | PResizeInc | PMinSize; + + /* subtract one for the right/bottom border */ + mysizehints.min_width = UWidth + interval - 1 + h_margin; + main_width = mysizehints.width = Width + h_margin; + mysizehints.min_height = UHeight + interval - 1 + v_margin; + main_height = mysizehints.height = Height + v_margin; + mysizehints.width_inc = UWidth; + mysizehints.height_inc = UHeight; + + if (x > -100000) { + if (xneg) { + mysizehints.x = + DisplayWidth(dpy, screen) + x - mysizehints.width; + gravity = NorthEastGravity; + } else + mysizehints.x = x; + if (yneg) { + mysizehints.y = + DisplayHeight(dpy, screen) + y - mysizehints.height; + gravity = SouthWestGravity; + } else + mysizehints.y = y; + + if ((xneg) && (yneg)) + gravity = SouthEastGravity; + + mysizehints.flags |= USPosition; + } - /* buttons */ - if (!(local_flags & HIDE_H)){ - attributes.win_gravity = SouthWestGravity; - l_button = XCreateWindow(dpy, main_win, margin1 + 2, - margin1 + 6 + Height + margin2, - bar_width, bar_width, - 0, CopyFromParent, - InputOutput, CopyFromParent, - mask, &attributes); - attributes.win_gravity = SouthEastGravity; - r_button = XCreateWindow(dpy, main_win, margin1 + 2 + Width - - bar_width, - margin1 + 6 + Height + margin2, - bar_width, bar_width, - 0, CopyFromParent, - InputOutput, CopyFromParent, - mask, &attributes); - XSelectInput(dpy,l_button,BUTTON_EVENTS); - XSelectInput(dpy,r_button,BUTTON_EVENTS); - } - if (!(local_flags & HIDE_V)){ - attributes.win_gravity = NorthEastGravity; - t_button = XCreateWindow(dpy, main_win, margin1 + 6 + - Width + margin2, margin1 + 2, - bar_width, bar_width, - 0, CopyFromParent, - InputOutput, CopyFromParent, - mask, &attributes); - attributes.win_gravity = SouthEastGravity; - b_button = XCreateWindow(dpy, main_win, margin1 + 6 + - Width + margin2, - margin1 + 2 + Height - bar_width, - bar_width, bar_width, - 0, CopyFromParent, - InputOutput, CopyFromParent, - mask, &attributes); - XSelectInput(dpy,t_button,BUTTON_EVENTS); - XSelectInput(dpy,b_button,BUTTON_EVENTS); - } + mysizehints.win_gravity = gravity; + + if (d_depth < 2) { + back_pix = icon_back_pix = act_icon_fore_pix = + GetColor("white"); + fore_pix = icon_fore_pix = act_icon_back_pix = + GetColor("black"); + hilite_pix = icon_hilite_pix = act_icon_shadow_pix = + icon_back_pix; + shadow_pix = icon_shadow_pix = act_icon_hilite_pix = + icon_fore_pix; + } else { + fore_pix = GetColor(Fore); + back_pix = GetColor(Back); + icon_back_pix = GetColor(IconBack); + icon_fore_pix = GetColor(IconFore); + icon_hilite_pix = GetHilite(icon_back_pix); + icon_shadow_pix = GetShadow(icon_back_pix); + act_icon_back_pix = GetColor(ActIconBack); + act_icon_fore_pix = GetColor(ActIconFore); + act_icon_hilite_pix = GetHilite(act_icon_back_pix); + act_icon_shadow_pix = GetShadow(act_icon_back_pix); + hilite_pix = GetHilite(back_pix); + shadow_pix = GetShadow(back_pix); + } + + main_win = XCreateSimpleWindow(dpy, Root, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, 0, fore_pix, back_pix); + XSetWMProtocols(dpy, main_win, &wm_del_win, 1); + XSelectInput(dpy, main_win, MW_EVENTS); + + /* set normal_hits, wm_hints, and, class_hints */ + list[0] = MyName; + list[1] = NULL; + if (XStringListToTextProperty(list, 1, &name) == 0) { + fprintf(stderr, "%s: cannot allocate window name", MyName); + return; + } + class_hints.res_name = MyName; + class_hints.res_class = "FvwmIconBox"; + XSetWMProperties(dpy, main_win, &name, &name, NULL, 0, &mysizehints, + NULL, &class_hints); + XFree(name.value); + + mysizehints.width -= h_margin; + mysizehints.height -= v_margin; + holder_win = + XCreateSimpleWindow(dpy, main_win, margin1 + 2, margin1 + 2, + mysizehints.width, mysizehints.height, 0, fore_pix, back_pix); + + icon_win = + XCreateSimpleWindow(dpy, holder_win, -icon_win_x, -icon_win_y, + icon_win_width, icon_win_height, 0, fore_pix, back_pix); + + gcm = GCForeground | GCBackground; + gcv.foreground = hilite_pix; + gcv.background = back_pix; + ReliefGC = XCreateGC(dpy, Root, gcm, &gcv); + + gcm = GCForeground | GCBackground; + gcv.foreground = shadow_pix; + gcv.background = back_pix; + ShadowGC = XCreateGC(dpy, Root, gcm, &gcv); + + gcm = GCForeground | GCBackground; + gcv.foreground = icon_hilite_pix; + gcv.background = icon_back_pix; + IconReliefGC = XCreateGC(dpy, Root, gcm, &gcv); + + gcm = GCForeground | GCBackground; + gcv.foreground = icon_shadow_pix; + gcv.background = icon_back_pix; + IconShadowGC = XCreateGC(dpy, Root, gcm, &gcv); + + gcm = GCForeground | GCBackground | GCFont; + gcv.foreground = fore_pix; + gcv.background = back_pix; + gcv.font = font->fid; + NormalGC = XCreateGC(dpy, Root, gcm, &gcv); + + /* icon_win's background */ + if (GetBackPixmap() == True) { + XSetWindowBackgroundPixmap(dpy, icon_win, IconwinPixmap); + /* special thanks to Dave Goldberg + for his helpful information */ + XFreePixmap(dpy, IconwinPixmap); + } + + XSetForeground(dpy, NormalGC, icon_fore_pix); + XSetBackground(dpy, NormalGC, icon_back_pix); + + /* scroll bars */ + mask = CWWinGravity | CWBackPixel; + attributes.background_pixel = back_pix; + if (!(local_flags & HIDE_H)) { + attributes.win_gravity = SouthWestGravity; + h_scroll_bar = XCreateWindow(dpy, main_win, + margin1 + 2 + bar_width, margin1 + 6 + Height + margin2, + Width - bar_width * 2, bar_width, 0, CopyFromParent, + InputOutput, CopyFromParent, mask, &attributes); + XSelectInput(dpy, h_scroll_bar, SCROLL_EVENTS); + } + if (!(local_flags & HIDE_V)) { + attributes.win_gravity = NorthEastGravity; + v_scroll_bar = XCreateWindow(dpy, main_win, + margin1 + 6 + Width + margin2, margin1 + 2 + bar_width, + bar_width, Height - bar_width * 2, 0, CopyFromParent, + InputOutput, CopyFromParent, mask, &attributes); + XSelectInput(dpy, v_scroll_bar, SCROLL_EVENTS); + } + + /* buttons */ + if (!(local_flags & HIDE_H)) { + attributes.win_gravity = SouthWestGravity; + l_button = XCreateWindow(dpy, main_win, margin1 + 2, + margin1 + 6 + Height + margin2, bar_width, bar_width, 0, + CopyFromParent, InputOutput, CopyFromParent, mask, + &attributes); + attributes.win_gravity = SouthEastGravity; + r_button = XCreateWindow(dpy, main_win, + margin1 + 2 + Width - bar_width, + margin1 + 6 + Height + margin2, bar_width, bar_width, 0, + CopyFromParent, InputOutput, CopyFromParent, mask, + &attributes); + XSelectInput(dpy, l_button, BUTTON_EVENTS); + XSelectInput(dpy, r_button, BUTTON_EVENTS); + } + if (!(local_flags & HIDE_V)) { + attributes.win_gravity = NorthEastGravity; + t_button = + XCreateWindow(dpy, main_win, margin1 + 6 + Width + margin2, + margin1 + 2, bar_width, bar_width, 0, CopyFromParent, + InputOutput, CopyFromParent, mask, &attributes); + attributes.win_gravity = SouthEastGravity; + b_button = + XCreateWindow(dpy, main_win, margin1 + 6 + Width + margin2, + margin1 + 2 + Height - bar_width, bar_width, bar_width, + 0, CopyFromParent, InputOutput, CopyFromParent, mask, + &attributes); + XSelectInput(dpy, t_button, BUTTON_EVENTS); + XSelectInput(dpy, b_button, BUTTON_EVENTS); + } } -void GetIconwinSize(int *dx, int *dy) +void +GetIconwinSize(int *dx, int *dy) { - *dx = icon_win_width; - *dy = icon_win_height; - - if (primary == LEFT || primary == RIGHT){ - icon_win_width = max(Width, UWidth * Lines + interval - 1); - icon_win_height = max(Height, UHeight * (max(0, - (num_icons-1))/Lines - + 1) - 1 + interval); - }else{ - icon_win_width = max(Width, UWidth * (max(0,num_icons-1) / Lines + - 1) + interval - 1); - icon_win_height = max(Height, UHeight * Lines - 1 + interval); - } - *dx = icon_win_width - *dx; - *dy = icon_win_height - *dy; + *dx = icon_win_width; + *dy = icon_win_height; + + if (primary == LEFT || primary == RIGHT) { + icon_win_width = max(Width, UWidth * Lines + interval - 1); + icon_win_height = max( + Height, UHeight * (max(0, (num_icons - 1)) / Lines + 1) - + 1 + interval); + } else { + icon_win_width = + max(Width, UWidth * (max(0, num_icons - 1) / Lines + 1) + + interval - 1); + icon_win_height = max(Height, UHeight * Lines - 1 + interval); + } + *dx = icon_win_width - *dx; + *dy = icon_win_height - *dy; } /************************************************************************ @@ -1138,33 +1262,31 @@ void GetIconwinSize(int *dx, int *dy) * Original work from GoodStuff: * Copyright 1993, Robert Nation. ***********************************************************************/ -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"%s: can't %s %s\n", MyName, a,b); + fprintf(stderr, "%s: can't %s %s\n", MyName, a, b); } - /************************************************************************ * GetColor * Original work from GoodStuff: * Copyright 1993, Robert Nation. ***********************************************************************/ -Pixel GetColor(char *name) +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(dpy,Root,&attributes); - color.pixel = 0; - if (!XParseColor (dpy, attributes.colormap, name, &color)) - { - nocolor("parse",name); - } - else if(!XAllocColor (dpy, attributes.colormap, &color)) - { - nocolor("alloc",name); - } - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(dpy, Root, &attributes); + color.pixel = 0; + if (!XParseColor(dpy, attributes.colormap, name, &color)) { + nocolor("parse", name); + } else if (!XAllocColor(dpy, attributes.colormap, &color)) { + nocolor("alloc", name); + } + return color.pixel; } /************************************************************************ @@ -1172,152 +1294,158 @@ Pixel GetColor(char *name) Original work from FvwmWinList: Copyright 1994, Mike Finger. ************************************************************************/ -void SendFvwmPipe(int *fd, char *message,unsigned long window) +void +SendFvwmPipe(int *fd, char *message, unsigned long window) { - int w; - char *hold,*temp,*temp_msg; - hold=message; - - while(1) { - temp=strchr(hold,','); - if (temp!=NULL) { - temp_msg=malloc(temp-hold+1); - strncpy(temp_msg,hold,(temp-hold)); - temp_msg[(temp-hold)]='\0'; - hold=temp+1; - } else temp_msg=hold; - - if (!ExecIconBoxFunction(temp_msg)){ - write(fd[0],&window, sizeof(unsigned long)); - - w=strlen(temp_msg); - write(fd[0],&w,sizeof(int)); - write(fd[0],temp_msg,w); - - /* keep going */ - w=1; - write(fd[0],&w,sizeof(int)); - - } - if(temp_msg!=hold) free(temp_msg); - else break; - } + int w; + char *hold, *temp, *temp_msg; + hold = message; + + while (1) { + temp = strchr(hold, ','); + if (temp != NULL) { + temp_msg = malloc(temp - hold + 1); + strncpy(temp_msg, hold, (temp - hold)); + temp_msg[(temp - hold)] = '\0'; + hold = temp + 1; + } else + temp_msg = hold; + + if (!ExecIconBoxFunction(temp_msg)) { + write(fd[0], &window, sizeof(unsigned long)); + + w = strlen(temp_msg); + write(fd[0], &w, sizeof(int)); + write(fd[0], temp_msg, w); + + /* keep going */ + w = 1; + write(fd[0], &w, sizeof(int)); + } + if (temp_msg != hold) + free(temp_msg); + else + break; + } } -Bool ExecIconBoxFunction(char *msg) +Bool +ExecIconBoxFunction(char *msg) { - if (strncasecmp(msg, "Next", 4) == 0){ - Next(); - return True; - }else if (strncasecmp(msg, "Prev", 4) == 0){ - Prev(); - return True; - }else if (strncasecmp(msg, "Left", 4) == 0){ - HScroll(icon_win_x - UWidth); - return True; - }else if (strncasecmp(msg, "Right", 5) == 0){ - HScroll(icon_win_x + UWidth); - return True; - }else if (strncasecmp(msg, "Up", 2) == 0){ - VScroll(icon_win_y - UHeight); - return True; - }else if (strncasecmp(msg, "Down", 4) == 0){ - VScroll(icon_win_y + UHeight); - return True; - } - return False; + if (strncasecmp(msg, "Next", 4) == 0) { + Next(); + return True; + } else if (strncasecmp(msg, "Prev", 4) == 0) { + Prev(); + return True; + } else if (strncasecmp(msg, "Left", 4) == 0) { + HScroll(icon_win_x - UWidth); + return True; + } else if (strncasecmp(msg, "Right", 5) == 0) { + HScroll(icon_win_x + UWidth); + return True; + } else if (strncasecmp(msg, "Up", 2) == 0) { + VScroll(icon_win_y - UHeight); + return True; + } else if (strncasecmp(msg, "Down", 4) == 0) { + VScroll(icon_win_y + UHeight); + return True; + } + return False; } -void Next(void) +void +Next(void) { - struct icon_info *new, *old; - int i; - - old = new = Hilite; - - if (new != NULL) - new = new->next; - - if (new != NULL) - Hilite = new; - else - new = Hilite = Head; - - if (new == NULL) - return; - - if (old != NULL) - RedrawIcon(old, redraw_flag); - if (new != NULL) - RedrawIcon(new, redraw_flag); - - i=0; - if (new->x < icon_win_x){ - while (new->x + UWidth * ++i < icon_win_x) - ; - HScroll(icon_win_x - UWidth*i); - }else if (new->x > icon_win_x + Width){ - while (new->x - UWidth * ++i > icon_win_x + Width) - ; - HScroll(icon_win_x + UWidth*i); - } + struct icon_info *new, *old; + int i; + + old = new = Hilite; + + if (new != NULL) + new = new->next; + + if (new != NULL) + Hilite = new; + else + new = Hilite = Head; + + if (new == NULL) + return; + + if (old != NULL) + RedrawIcon(old, redraw_flag); + if (new != NULL) + RedrawIcon(new, redraw_flag); + + i = 0; + if (new->x < icon_win_x) { + while (new->x + UWidth * ++i < icon_win_x) + ; + HScroll(icon_win_x - UWidth * i); + } else if (new->x > icon_win_x + Width) { + while (new->x - UWidth * ++i > icon_win_x + Width) + ; + HScroll(icon_win_x + UWidth * i); + } - i=0; - if (new->y < icon_win_y){ - while (new->y + UHeight * ++i < icon_win_y) - ; - VScroll(icon_win_y - UHeight*i); - }else if (new->y > icon_win_y + Height){ - while (new->y - UHeight * ++i > icon_win_y + Height) - ; - VScroll(icon_win_y + UHeight*i); - } + i = 0; + if (new->y < icon_win_y) { + while (new->y + UHeight * ++i < icon_win_y) + ; + VScroll(icon_win_y - UHeight * i); + } else if (new->y > icon_win_y + Height) { + while (new->y - UHeight * ++i > icon_win_y + Height) + ; + VScroll(icon_win_y + UHeight * i); + } } -void Prev(void) +void +Prev(void) { - struct icon_info *new, *old; - int i; - - old = new = Hilite; - - if (new != NULL) - new = new->prev; - - if (new != NULL) - Hilite = new; - else - new = Hilite = Tail; - - if (new == NULL) - return; - - if (old != NULL) - RedrawIcon(old, redraw_flag); - if (new != NULL) - RedrawIcon(new, redraw_flag); - - i=0; - if (new->x < icon_win_x){ - while (new->x + UWidth * ++i < icon_win_x) - ; - HScroll(icon_win_x - UWidth*i); - }else if (new->x > icon_win_x + Width){ - while (new->x - UWidth * ++i > icon_win_x + Width) - ; - HScroll(icon_win_x + UWidth*i); - } + struct icon_info *new, *old; + int i; + + old = new = Hilite; + + if (new != NULL) + new = new->prev; + + if (new != NULL) + Hilite = new; + else + new = Hilite = Tail; + + if (new == NULL) + return; + + if (old != NULL) + RedrawIcon(old, redraw_flag); + if (new != NULL) + RedrawIcon(new, redraw_flag); + + i = 0; + if (new->x < icon_win_x) { + while (new->x + UWidth * ++i < icon_win_x) + ; + HScroll(icon_win_x - UWidth * i); + } else if (new->x > icon_win_x + Width) { + while (new->x - UWidth * ++i > icon_win_x + Width) + ; + HScroll(icon_win_x + UWidth * i); + } - i=0; - if (new->y < icon_win_y){ - while (new->y + UHeight * ++i < icon_win_y) - ; - VScroll(icon_win_y - UHeight*i); - }else if (new->y > icon_win_y + Height){ - while (new->y - UHeight * ++i > icon_win_y + Height) - ; - VScroll(icon_win_y + UHeight*i); - } + i = 0; + if (new->y < icon_win_y) { + while (new->y + UHeight * ++i < icon_win_y) + ; + VScroll(icon_win_y - UHeight * i); + } else if (new->y > icon_win_y + Height) { + while (new->y - UHeight * ++i > icon_win_y + Height) + ; + VScroll(icon_win_y + UHeight * i); + } } /************************************************************************ @@ -1325,425 +1453,438 @@ void Prev(void) * Based on DeadPipe() from GoodStuff: * Copyright 1993, Robert Nation. ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { -#if 0 /* can't do X or malloc stuff in a signal handler, so just exit */ - struct icon_info *tmpi, *tmpi2; - struct mousefunc *tmpm, *tmpm2; - struct keyfunc *tmpk, *tmpk2; - struct iconfile *tmpf, *tmpf2; - - if (FvwmDefaultIcon != NULL) - free(FvwmDefaultIcon); - - tmpm = MouseActions; - while(tmpm != NULL){ - tmpm2 = tmpm; - tmpm = tmpm->next; - free(tmpm2->action); - free(tmpm2); - } - - tmpk = KeyActions; - while(tmpk != NULL){ - tmpk2 = tmpk; - tmpk = tmpk->next; - free(tmpk2->action); - free(tmpk2->name); - free(tmpk2); - } - - tmpf = IconListHead; - while(tmpf != NULL){ - tmpf2 = tmpf; - tmpf = tmpf->next; - free(tmpf2->name); - free(tmpf2->iconfile); - free(tmpf2); - } - - tmpi = Head; - while(tmpi != NULL){ - tmpi2 = tmpi; - tmpi = tmpi->next; - freeitem(tmpi2, 0); - } - if ((local_flags & SETWMICONSIZE)) - XDeleteProperty(dpy, Root, XA_WM_ICON_SIZE); - XSync(dpy,0); -#endif /* 0 */ - exit(0); + exit(0); } - /************************************************************************ * ParseOptions * Based on ParseConfig() from FvwmWinList: * Copyright 1994, Mike Finger. ***********************************************************************/ -void ParseOptions(void) +void +ParseOptions(void) { - char *tline= NULL,*tmp; - int Clength; - - Clength = strlen(MyName); - - GetConfigLine(fd,&tline); - - while(tline != NULL) - { - int g_x, g_y, flags; - unsigned width,height; - - if(strlen(&tline[0])>1){ - if (strncasecmp(tline,CatString3("*", MyName, - "Geometry"),Clength+9)==0){ - tmp = &tline[Clength+9]; - while(((isspace(*tmp))&&(*tmp != '\n'))&&(*tmp != 0)) - tmp++; - tmp[strlen(tmp)-1] = 0; - flags = XParseGeometry(tmp,&g_x,&g_y,&width,&height); - if (flags & WidthValue) - num_columns = width; - if (flags & HeightValue) - num_rows = height; - if (flags & XValue) - x = g_x; - if (flags & YValue) - y = g_y; - if (flags & XNegative) - xneg = 1; - if (flags & YNegative) - yneg = 1; - } else if (strncasecmp(tline,CatString3("*", MyName, - "MaxIconSize"),Clength+12)==0){ - tmp = &tline[Clength+12]; - while(((isspace(*tmp))&&(*tmp != '\n'))&&(*tmp != 0)) - tmp++; - tmp[strlen(tmp)-1] = 0; - - flags = XParseGeometry(tmp,&g_x,&g_y,&width,&height); - if (flags & WidthValue) - max_icon_width = width; - if (flags & HeightValue) - max_icon_height = height; - if (height == 0){ - icon_relief = 0; - redraw_flag = 2; - max_icon_width += 4; - } - }else if - (strncasecmp(tline,CatString3("*",MyName,"Font"),Clength+5)==0) - CopyString(&font_string,&tline[Clength+5]); - else if - (strncasecmp(tline,CatString3("*",MyName,"IconFore"),Clength+9)==0) - CopyString(&IconFore,&tline[Clength+9]); - else if - (strncasecmp(tline,CatString3("*",MyName,"IconBack"),Clength+9)==0) - CopyString(&IconBack,&tline[Clength+9]); - else if - (strncasecmp(tline,CatString3("*",MyName,"IconHiFore"),Clength+11)==0) - CopyString(&ActIconFore,&tline[Clength+11]); - else if - (strncasecmp(tline,CatString3("*",MyName,"IconHiBack"),Clength+11)==0) - CopyString(&ActIconBack,&tline[Clength+11]); - else if (strncasecmp(tline,CatString3("*",MyName, - "Fore"),Clength+5)==0) - CopyString(&Fore,&tline[Clength+5]); - else if (strncasecmp(tline,CatString3("*",MyName, - "Back"),Clength+5)==0) - CopyString(&Back,&tline[Clength+5]); - else if (strncasecmp(tline,CatString3("*",MyName, - "Pixmap"),Clength+7)==0) - CopyString(&IconwinPixmapFile,&tline[Clength+7]); - else if (strncasecmp(tline,CatString3("*",MyName, - "Padding"),Clength+8)==0) - interval = max(0,atoi(&tline[Clength+8])); - else if (strncasecmp(tline,CatString3("*",MyName, - "FrameWidth"),Clength+11)==0){ - sscanf(&tline[Clength+11], "%d %d", &margin1, &margin2); - margin1 = max(0, margin1); - margin2 = max(0, margin2); - }else if (strncasecmp(tline,CatString3("*",MyName, - "Lines"),Clength+6)==0) - Lines = max(1,atoi(&tline[Clength+6])); - else if (strncasecmp(tline,CatString3("*",MyName, - "SBWidth"),Clength+8)==0) - bar_width = max(5,atoi(&tline[Clength+8])); - else if (strncasecmp(tline,CatString3("*",MyName, - "Placement"),Clength+10)==0) - parseplacement(&tline[Clength+10]); - else if (strncasecmp(tline,CatString3("*",MyName, - "SetWMIconSize"),Clength+14)==0) - local_flags |= SETWMICONSIZE; - else if (strncasecmp(tline,CatString3("*",MyName, - "HilightFocusWin"),Clength+16)==0) - m_mask |= M_FOCUS_CHANGE; - else if (strncasecmp(tline,CatString3("*",MyName, - "Resolution"),Clength+11)==0){ - tmp = &tline[Clength+11]; - while(((isspace(*tmp))&&(*tmp != '\n'))&&(*tmp != 0)) - tmp++; - if (strncasecmp(tmp, "Desk", 4) == 0){ - m_mask |= M_NEW_DESK; - local_flags |= CURRENT_ONLY; - } - }else if (strncasecmp(tline,CatString3("*",MyName, - "Mouse"),Clength+6)==0) - parsemouse(&tline[Clength + 6]); - else if (strncasecmp(tline,CatString3("*",MyName, - "Key"),Clength+4)==0) - parsekey(&tline[Clength + 4]); - else if (strncasecmp(tline,CatString3("*",MyName, - "SortIcons"),Clength+10)==0){ - tmp = &tline[Clength+10]; - while(((isspace(*tmp))&&(*tmp != '\n'))&&(*tmp != 0)) - tmp++; - if (strlen(tmp) == 0){ /* the case where no argument is given */ - sortby = ICONNAME; - return; - } - if (strncasecmp(tmp, "WindowName", 10) == 0) - sortby = WINDOWNAME; - else if (strncasecmp(tmp, "IconName", 8) == 0) - sortby = ICONNAME; - else if (strncasecmp(tmp, "ResClass", 8) == 0) - sortby = RESCLASS; - else if (strncasecmp(tmp, "ResName", 7) == 0) - sortby = RESNAME; - }else if (strncasecmp(tline,CatString3("*",MyName, - "HideSC"),Clength+7)==0){ - tmp = &tline[Clength+7]; - while(((isspace(*tmp))&&(*tmp != '\n'))&&(*tmp != 0)) - tmp++; - if (strncasecmp(tmp, "Horizontal", 10) == 0) - local_flags |= HIDE_H; - else if (strncasecmp(tmp, "Vertical", 8) == 0) - local_flags |= HIDE_V; - }else if (strncasecmp(tline,CatString3("*",MyName, - ""),Clength+1)==0) - parseicon(&tline[Clength + 1]); - else if (strncasecmp(tline,"IconPath",8)==0) - CopyString(&iconPath,&tline[8]); - else if (strncasecmp(tline,"PixmapPath",10)==0) - CopyString(&pixmapPath,&tline[10]); - else if (strncasecmp(tline,"ClickTime",9)==0) - ClickTime = atoi(&tline[9]); - else if (strncasecmp(tline,"ColorLimit",10)==0) { - save_color_limit = atoi(&tline[10]); - } - } - GetConfigLine(fd,&tline); - } - - return; + char *tline = NULL, *tmp; + int Clength; + + Clength = strlen(MyName); + + GetConfigLine(fd, &tline); + + while (tline != NULL) { + int g_x, g_y, flags; + unsigned width, height; + + if (strlen(&tline[0]) > 1) { + if (strncasecmp(tline, + CatString3("*", MyName, "Geometry"), + Clength + 9) == 0) { + tmp = &tline[Clength + 9]; + while (((isspace(*tmp)) && (*tmp != '\n')) && + (*tmp != 0)) + tmp++; + tmp[strlen(tmp) - 1] = 0; + flags = XParseGeometry( + tmp, &g_x, &g_y, &width, &height); + if (flags & WidthValue) + num_columns = width; + if (flags & HeightValue) + num_rows = height; + if (flags & XValue) + x = g_x; + if (flags & YValue) + y = g_y; + if (flags & XNegative) + xneg = 1; + if (flags & YNegative) + yneg = 1; + } else if (strncasecmp(tline, + CatString3("*", MyName, "MaxIconSize"), + Clength + 12) == 0) { + tmp = &tline[Clength + 12]; + while (((isspace(*tmp)) && (*tmp != '\n')) && + (*tmp != 0)) + tmp++; + tmp[strlen(tmp) - 1] = 0; + + flags = XParseGeometry( + tmp, &g_x, &g_y, &width, &height); + if (flags & WidthValue) + max_icon_width = width; + if (flags & HeightValue) + max_icon_height = height; + if (height == 0) { + icon_relief = 0; + redraw_flag = 2; + max_icon_width += 4; + } + } else if (strncasecmp(tline, + CatString3("*", MyName, "Font"), + Clength + 5) == 0) + CopyString(&font_string, &tline[Clength + 5]); + else if (strncasecmp(tline, + CatString3("*", MyName, "IconFore"), + Clength + 9) == 0) + CopyString(&IconFore, &tline[Clength + 9]); + else if (strncasecmp(tline, + CatString3("*", MyName, "IconBack"), + Clength + 9) == 0) + CopyString(&IconBack, &tline[Clength + 9]); + else if (strncasecmp(tline, + CatString3("*", MyName, "IconHiFore"), + Clength + 11) == 0) + CopyString(&ActIconFore, &tline[Clength + 11]); + else if (strncasecmp(tline, + CatString3("*", MyName, "IconHiBack"), + Clength + 11) == 0) + CopyString(&ActIconBack, &tline[Clength + 11]); + else if (strncasecmp(tline, + CatString3("*", MyName, "Fore"), + Clength + 5) == 0) + CopyString(&Fore, &tline[Clength + 5]); + else if (strncasecmp(tline, + CatString3("*", MyName, "Back"), + Clength + 5) == 0) + CopyString(&Back, &tline[Clength + 5]); + else if (strncasecmp(tline, + CatString3("*", MyName, "Pixmap"), + Clength + 7) == 0) + CopyString( + &IconwinPixmapFile, &tline[Clength + 7]); + else if (strncasecmp(tline, + CatString3("*", MyName, "Padding"), + Clength + 8) == 0) + interval = max(0, atoi(&tline[Clength + 8])); + else if (strncasecmp(tline, + CatString3("*", MyName, "FrameWidth"), + Clength + 11) == 0) { + sscanf(&tline[Clength + 11], "%d %d", &margin1, + &margin2); + margin1 = max(0, margin1); + margin2 = max(0, margin2); + } else if (strncasecmp(tline, + CatString3("*", MyName, "Lines"), + Clength + 6) == 0) + Lines = max(1, atoi(&tline[Clength + 6])); + else if (strncasecmp(tline, + CatString3("*", MyName, "SBWidth"), + Clength + 8) == 0) + bar_width = max(5, atoi(&tline[Clength + 8])); + else if (strncasecmp(tline, + CatString3("*", MyName, "Placement"), + Clength + 10) == 0) + parseplacement(&tline[Clength + 10]); + else if (strncasecmp(tline, + CatString3("*", MyName, "SetWMIconSize"), + Clength + 14) == 0) + local_flags |= SETWMICONSIZE; + else if (strncasecmp(tline, + CatString3("*", MyName, "HilightFocusWin"), + Clength + 16) == 0) + m_mask |= M_FOCUS_CHANGE; + else if (strncasecmp(tline, + CatString3("*", MyName, "Resolution"), + Clength + 11) == 0) { + tmp = &tline[Clength + 11]; + while (((isspace(*tmp)) && (*tmp != '\n')) && + (*tmp != 0)) + tmp++; + if (strncasecmp(tmp, "Desk", 4) == 0) { + m_mask |= M_NEW_DESK; + local_flags |= CURRENT_ONLY; + } + } else if (strncasecmp(tline, + CatString3("*", MyName, "Mouse"), + Clength + 6) == 0) + parsemouse(&tline[Clength + 6]); + else if (strncasecmp(tline, + CatString3("*", MyName, "Key"), + Clength + 4) == 0) + parsekey(&tline[Clength + 4]); + else if (strncasecmp(tline, + CatString3("*", MyName, "SortIcons"), + Clength + 10) == 0) { + tmp = &tline[Clength + 10]; + while (((isspace(*tmp)) && (*tmp != '\n')) && + (*tmp != 0)) + tmp++; + if (strlen(tmp) == 0) { /* the case where no + argument is given */ + sortby = ICONNAME; + return; + } + if (strncasecmp(tmp, "WindowName", 10) == 0) + sortby = WINDOWNAME; + else if (strncasecmp(tmp, "IconName", 8) == 0) + sortby = ICONNAME; + else if (strncasecmp(tmp, "ResClass", 8) == 0) + sortby = RESCLASS; + else if (strncasecmp(tmp, "ResName", 7) == 0) + sortby = RESNAME; + } else if (strncasecmp(tline, + CatString3("*", MyName, "HideSC"), + Clength + 7) == 0) { + tmp = &tline[Clength + 7]; + while (((isspace(*tmp)) && (*tmp != '\n')) && + (*tmp != 0)) + tmp++; + if (strncasecmp(tmp, "Horizontal", 10) == 0) + local_flags |= HIDE_H; + else if (strncasecmp(tmp, "Vertical", 8) == 0) + local_flags |= HIDE_V; + } else if (strncasecmp(tline, + CatString3("*", MyName, ""), + Clength + 1) == 0) + parseicon(&tline[Clength + 1]); + else if (strncasecmp(tline, "IconPath", 8) == 0) + CopyString(&iconPath, &tline[8]); + else if (strncasecmp(tline, "PixmapPath", 10) == 0) + CopyString(&pixmapPath, &tline[10]); + else if (strncasecmp(tline, "ClickTime", 9) == 0) + ClickTime = atoi(&tline[9]); + else if (strncasecmp(tline, "ColorLimit", 10) == 0) { + save_color_limit = atoi(&tline[10]); + } + } + GetConfigLine(fd, &tline); + } + + return; } -void parseicon(char *tline) +void +parseicon(char *tline) { - int len; - struct iconfile *tmp; - char *ptr, *start, *end; - - tmp = (struct iconfile *)safemalloc(sizeof(struct iconfile)); - - - /* windowname */ - tmp->name = stripcpy2(tline); - if(tmp->name == NULL){ - free(tmp); - return; - } - - /* skip windowname, based on strpcpy3 of configure.c */ - while((*tline != '"')&&(tline != NULL)) - tline++; - if(*tline != 0) - tline++; - while((*tline != '"')&&(tline != NULL)) - tline++; - if(*tline == 0){ - free(tmp); - return; - } - tline++; - - /* file */ - /* skip spaces */ - while(isspace(*tline)&&(*tline != '\n')&&(*tline != 0)) - tline++; - start = tline; - end = tline; - while(!isspace(*end)&&(*end != '\n')&&(*end != 0)) - end++; - len = end - start; - ptr = safemalloc(len+1); - strncpy(ptr, start, len); - ptr[len] = 0; - tmp->iconfile = ptr; - - if (strcmp(tmp->name, "*") == 0) - DefaultIcon = tmp; - - tmp->next = NULL; - - if (IconListHead == NULL) - IconListHead = IconListTail = tmp; - else{ - IconListTail->next = tmp; - IconListTail = tmp; - } + int len; + struct iconfile *tmp; + char *ptr, *start, *end; + + tmp = (struct iconfile *)xmalloc(sizeof(struct iconfile)); + + /* windowname */ + tmp->name = stripcpy2(tline); + if (tmp->name == NULL) { + free(tmp); + return; + } + + /* skip windowname, based on strpcpy3 of configure.c */ + while ((*tline != '"') && (tline != NULL)) + tline++; + if (*tline != 0) + tline++; + while ((*tline != '"') && (tline != NULL)) + tline++; + if (*tline == 0) { + free(tmp); + return; + } + tline++; + + /* file */ + /* skip spaces */ + while (isspace(*tline) && (*tline != '\n') && (*tline != 0)) + tline++; + start = tline; + end = tline; + while (!isspace(*end) && (*end != '\n') && (*end != 0)) + end++; + len = end - start; + ptr = xmalloc(len + 1); + strncpy(ptr, start, len); + ptr[len] = 0; + tmp->iconfile = ptr; + + if (strcmp(tmp->name, "*") == 0) + DefaultIcon = tmp; + + tmp->next = NULL; + + if (IconListHead == NULL) + IconListHead = IconListTail = tmp; + else { + IconListTail->next = tmp; + IconListTail = tmp; + } } -void parseplacement(char *tline) +void +parseplacement(char *tline) { - char p[240], s[240]; - - sscanf(tline, "%s %s", p, s); - - if (strncasecmp(p, "Left", 4) == 0) - primary = LEFT; - else if (strncasecmp(p, "Right", 5) == 0) - primary = RIGHT; - else if (strncasecmp(p, "Top", 3) == 0) - primary = TOP; - else if (strncasecmp(p, "Bottom", 6) == 0) - primary = BOTTOM; - - if (strncasecmp(s, "Left", 4) == 0) - secondary = LEFT; - else if (strncasecmp(s, "Right", 5) == 0) - secondary = RIGHT; - else if (strncasecmp(s, "Top", 3) == 0) - secondary = TOP; - else if (strncasecmp(s, "Bottom", 6) == 0) - secondary = BOTTOM; + char p[240], s[240]; + + sscanf(tline, "%s %s", p, s); + + if (strncasecmp(p, "Left", 4) == 0) + primary = LEFT; + else if (strncasecmp(p, "Right", 5) == 0) + primary = RIGHT; + else if (strncasecmp(p, "Top", 3) == 0) + primary = TOP; + else if (strncasecmp(p, "Bottom", 6) == 0) + primary = BOTTOM; + + if (strncasecmp(s, "Left", 4) == 0) + secondary = LEFT; + else if (strncasecmp(s, "Right", 5) == 0) + secondary = RIGHT; + else if (strncasecmp(s, "Top", 3) == 0) + secondary = TOP; + else if (strncasecmp(s, "Bottom", 6) == 0) + secondary = BOTTOM; } -void parsemouse(char *tline) +void +parsemouse(char *tline) { - struct mousefunc *f = NULL; - int len; - char *ptr,*start,*end,*tmp; - - f = (struct mousefunc *)safemalloc(sizeof(struct mousefunc)); - f->next = NULL; - f->mouse = 0; - - /* skip spaces */ - while(isspace(*tline)&&(*tline != '\n')&&(*tline != 0)) - tline++; - start = tline; - end = tline; - while((!isspace(*end))&&(*end!='\n')&&(*end!=0)) - end++; - if (strncasecmp(start, "1", 1) == 0) - f->mouse = Button1; - else if (strncasecmp(start, "2", 1) == 0) - f->mouse = Button2; - else if (strncasecmp(start, "3", 1) == 0) - f->mouse = Button3; - /* click or doubleclick */ - tline = end; - /* skip spaces */ - while(isspace(*tline)&&(*tline != '\n')&&(*tline != 0)) - tline++; - start = tline; - end = tline; - while((!isspace(*end))&&(*end!='\n')&&(*end!=0)) - end++; - if (strncasecmp(start, "Click", 5) == 0) - f->type = CLICK; - else if (strncasecmp(start, "DoubleClick", 11) == 0) - f->type = DOUBLE_CLICK; - - /* actions */ - tline = end; - /* skip spaces */ - while(isspace(*tline)&&(*tline != '\n')&&(*tline != 0)) - tline++; - start = tline; - end = tline; - tmp = tline; - while((*tmp!='\n')&&(*tmp!=0)){ - if (!isspace(*tmp)) - end = tmp; - tmp++; - } - end++; - len = end - start; - ptr = safemalloc(len+1); - strncpy(ptr, start, len); - ptr[len] = 0; - f->action = ptr; - f->next = MouseActions; - MouseActions = f; + struct mousefunc *f = NULL; + int len; + char *ptr, *start, *end, *tmp; + + f = (struct mousefunc *)xmalloc(sizeof(struct mousefunc)); + f->next = NULL; + f->mouse = 0; + + /* skip spaces */ + while (isspace(*tline) && (*tline != '\n') && (*tline != 0)) + tline++; + start = tline; + end = tline; + while ((!isspace(*end)) && (*end != '\n') && (*end != 0)) + end++; + if (strncasecmp(start, "1", 1) == 0) + f->mouse = Button1; + else if (strncasecmp(start, "2", 1) == 0) + f->mouse = Button2; + else if (strncasecmp(start, "3", 1) == 0) + f->mouse = Button3; + /* click or doubleclick */ + tline = end; + /* skip spaces */ + while (isspace(*tline) && (*tline != '\n') && (*tline != 0)) + tline++; + start = tline; + end = tline; + while ((!isspace(*end)) && (*end != '\n') && (*end != 0)) + end++; + if (strncasecmp(start, "Click", 5) == 0) + f->type = CLICK; + else if (strncasecmp(start, "DoubleClick", 11) == 0) + f->type = DOUBLE_CLICK; + + /* actions */ + tline = end; + /* skip spaces */ + while (isspace(*tline) && (*tline != '\n') && (*tline != 0)) + tline++; + start = tline; + end = tline; + tmp = tline; + while ((*tmp != '\n') && (*tmp != 0)) { + if (!isspace(*tmp)) + end = tmp; + tmp++; + } + end++; + len = end - start; + ptr = xmalloc(len + 1); + strncpy(ptr, start, len); + ptr[len] = 0; + f->action = ptr; + f->next = MouseActions; + MouseActions = f; } /*********************************************************************** parsekey - Based on part of AddFunckey() of configure.c in Fvwm. - Copyright 1988, Evans and Sutherland Computer Corporation, - Copyright 1989, Massachusetts Institute of Technology, - Copyright 1993, Robert Nation. + Based on part of AddFunckey() of configure.c in Fvwm. + Copyright 1988, Evans and Sutherland Computer Corporation, + Copyright 1989, Massachusetts Institute of Technology, + Copyright 1993, Robert Nation. ***********************************************************************/ -void parsekey(char *tline) +void +parsekey(char *tline) { - struct keyfunc *k; - int nlen, alen; - char *nptr, *aptr, *start, *end, *tmp; - int i, kmin, kmax; - KeySym keysym; - - /* skip spaces */ - while(isspace(*tline)&&(*tline != '\n')&&(*tline != 0)) - tline++; - start = tline; - end = tline; - while((!isspace(*end))&&(*end!='\n')&&(*end!=0)) - end++; - nlen = end - start; - nptr = safemalloc(nlen+1); - strncpy(nptr, start, nlen); - nptr[nlen] = 0; - - /* actions */ - tline = end; - /* skip spaces */ - while(isspace(*tline)&&(*tline != '\n')&&(*tline != 0)) - tline++; - start = tline; - end = tline; - tmp = tline; - while((*tmp!='\n')&&(*tmp!=0)){ - if (!isspace(*tmp)) - end = tmp; - tmp++; - } - end++; - alen = end - start; - aptr = safemalloc(alen+1); - strncpy(aptr, start, alen); - aptr[alen] = 0; - - if ((keysym = XStringToKeysym(nptr)) == NoSymbol || - XKeysymToKeycode(dpy, keysym) == 0){ - free(nptr); - free(aptr); - return; - } + struct keyfunc *k; + int nlen, alen; + char *nptr, *aptr, *start, *end, *tmp; + int i, kmin, kmax; + KeySym keysym; + + /* skip spaces */ + while (isspace(*tline) && (*tline != '\n') && (*tline != 0)) + tline++; + start = tline; + end = tline; + while ((!isspace(*end)) && (*end != '\n') && (*end != 0)) + end++; + nlen = end - start; + nptr = xmalloc(nlen + 1); + strncpy(nptr, start, nlen); + nptr[nlen] = 0; + + /* actions */ + tline = end; + /* skip spaces */ + while (isspace(*tline) && (*tline != '\n') && (*tline != 0)) + tline++; + start = tline; + end = tline; + tmp = tline; + while ((*tmp != '\n') && (*tmp != 0)) { + if (!isspace(*tmp)) + end = tmp; + tmp++; + } + end++; + alen = end - start; + aptr = xmalloc(alen + 1); + strncpy(aptr, start, alen); + aptr[alen] = 0; + + if ((keysym = XStringToKeysym(nptr)) == NoSymbol || + XKeysymToKeycode(dpy, keysym) == 0) { + free(nptr); + free(aptr); + return; + } - XDisplayKeycodes(dpy, &kmin, &kmax); - for (i=kmin; i<=kmax; i++) - if (XKeycodeToKeysym(dpy, i, 0) == keysym) - { - k = (struct keyfunc *)safemalloc(sizeof(struct keyfunc)); - k->name = nptr; - k->keycode = i; - k->action = aptr; - k->next = KeyActions; - KeyActions = k; - } + XDisplayKeycodes(dpy, &kmin, &kmax); + { + Bool matched = False; + + for (i = kmin; i <= kmax; i++) { + KeySym *mapping; + int width; + + mapping = XGetKeyboardMapping(dpy, i, 1, &width); + if (mapping == NULL) + continue; + + for (int col = 0; col < width; col++) { + if (mapping[col] == keysym) { + k = (struct keyfunc *)xmalloc( + sizeof(struct keyfunc)); + k->name = nptr; + k->keycode = i; + k->action = aptr; + k->next = KeyActions; + KeyActions = k; + matched = True; + break; + } + } + XFree(mapping); + } + + if (!matched) { + free(nptr); + free(aptr); + } + } } /*********************************************************************** @@ -1751,18 +1892,18 @@ void parsekey(char *tline) * Original work from GoodStuff: * Copyright 1993, Robert Nation. ***********************************************************************/ -void change_window_name(char *str) +void +change_window_name(char *str) { - XTextProperty name; - - if (XStringListToTextProperty(&str,1,&name) == 0) - { - fprintf(stderr,"%s: cannot allocate window name",MyName); - return; - } - XSetWMName(dpy,main_win,&name); - XSetWMIconName(dpy,main_win,&name); - XFree(name.value); + XTextProperty name; + + if (XStringListToTextProperty(&str, 1, &name) == 0) { + fprintf(stderr, "%s: cannot allocate window name", MyName); + return; + } + XSetWMName(dpy, main_win, &name); + XSetWMIconName(dpy, main_win, &name); + XFree(name.value); } /*********************************************************************** @@ -1770,48 +1911,43 @@ void change_window_name(char *str) * Original work from GoodStuff: * Copyright 1993, Robert Nation. ***********************************************************************/ -int My_XNextEvent(Display *dpy, XEvent *event) +int +My_XNextEvent(Display *dpy, XEvent *event) { - fd_set in_fdset; - unsigned long header[HEADER_SIZE]; - static int miss_counter = 0; - unsigned long *body; - - if(XPending(dpy)) - { - XNextEvent(dpy,event); - return 1; - } - - FD_ZERO(&in_fdset); - FD_SET(x_fd,&in_fdset); - FD_SET(fd[1],&in_fdset); - - select(fd_width,SELECT_TYPE_ARG234 &in_fdset, 0, 0, NULL); - - if(FD_ISSET(x_fd, &in_fdset)) - { - if(XPending(dpy)) - { - XNextEvent(dpy,event); - miss_counter = 0; - return 1; - } - else - miss_counter++; - if(miss_counter > 100) - DeadPipe(0); - } - - if(FD_ISSET(fd[1], &in_fdset)) - { - if(ReadFvwmPacket(fd[1],header,&body) > 0) - { - process_message(header[1],body); - free(body); + fd_set in_fdset; + unsigned long header[HEADER_SIZE]; + static int miss_counter = 0; + unsigned long *body; + + if (XPending(dpy)) { + XNextEvent(dpy, event); + return 1; + } + + FD_ZERO(&in_fdset); + FD_SET(x_fd, &in_fdset); + FD_SET(fd[1], &in_fdset); + + select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL); + + if (FD_ISSET(x_fd, &in_fdset)) { + if (XPending(dpy)) { + XNextEvent(dpy, event); + miss_counter = 0; + return 1; + } else + miss_counter++; + if (miss_counter > 100) + DeadPipe(0); + } + + if (FD_ISSET(fd[1], &in_fdset)) { + if (ReadFvwmPacket(fd[1], header, &body) > 0) { + process_message(header[1], body); + free(body); + } } - } - return 0; + return 0; } /************************************************************************** @@ -1820,275 +1956,329 @@ int My_XNextEvent(Display *dpy, XEvent *event) * Copyright 1994, Mike Finger. *************************************************************************/ int diffx, diffy; -void process_message(unsigned long type, unsigned long *body) +void +process_message(unsigned long type, unsigned long *body) { - struct icon_info *tmp, *old; - char *str; - long olddesk; - - switch(type){ - case M_CONFIGURE_WINDOW: - if (ready){ - if (!(local_flags & CURRENT_ONLY)) break; - tmp = Head; - while(tmp != NULL){ - if (tmp->id == body[0]){ - if ((tmp->desk != body[7]) && !(tmp->flags & STICKY)){ - olddesk = tmp->desk; - tmp->desk = body[7]; - if (olddesk == CurrentDesk || tmp->desk == CurrentDesk){ - if (tmp->desk == CurrentDesk && sortby != UNSORT) - SortItem(NULL); - num_icons = AdjustIconWindows(); - GetIconwinSize(&diffx, &diffy); - if (diffy && (primary == BOTTOM || secondary == BOTTOM)) - icon_win_y += diffy; - if (diffx && (primary == RIGHT || secondary == RIGHT)) - icon_win_x += diffx; - if (icon_win_y < 0) - icon_win_y = 0; - if (icon_win_x < 0) - icon_win_x = 0; - if (icon_win_x + Width > icon_win_width) - icon_win_x = icon_win_width - Width; - if (icon_win_y + Height > icon_win_height) - icon_win_y = icon_win_height - Height; - XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y, - icon_win_width, icon_win_height); - if (tmp->desk == CurrentDesk){ - XMapWindow(dpy, tmp->IconWin); - if (max_icon_height != 0) - XMapWindow(dpy, tmp->icon_pixmap_w); - }else{ - XUnmapWindow(dpy, tmp->IconWin); - if (max_icon_height != 0) - XUnmapWindow(dpy, tmp->icon_pixmap_w); - } - if (!(local_flags & HIDE_H) && diffx) - RedrawHScrollbar(); - if (!(local_flags & HIDE_V) && diffy) - RedrawVScrollbar(); - } - }else if ((body[8] & STICKY) && !(tmp->flags & STICKY)) /* stick */ - tmp->flags |= STICKY; - else if (!(body[8] & STICKY) && (tmp->flags & STICKY)){ /* unstick */ - tmp->flags &= ~STICKY; - tmp->desk = body[7]; - } - return; - } - tmp = tmp->next; - } - break; - } - case M_ADD_WINDOW: - if (AddItem(body[0], body[7], body[8]) == True && ready){ - GetIconwinSize(&diffx, &diffy); - if (diffy && (primary == BOTTOM || secondary == BOTTOM)) - icon_win_y += diffy; - if (diffx && (primary == RIGHT || secondary == RIGHT)) - icon_win_x += diffx; - XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y, - icon_win_width, icon_win_height); - } - break; - case M_DESTROY_WINDOW: - if (DeleteItem(body[0]) && ready){ - GetIconwinSize(&diffx, &diffy); - if (diffy && (primary == BOTTOM || secondary == BOTTOM)) - icon_win_y += diffy; - if (diffx && (primary == RIGHT || secondary == RIGHT)) - icon_win_x += diffx; - if (icon_win_y < 0) - icon_win_y = 0; - if (icon_win_x < 0) - icon_win_x = 0; - if (icon_win_x + Width > icon_win_width) - icon_win_x = icon_win_width - Width; - if (icon_win_y + Height > icon_win_height) - icon_win_y = icon_win_height - Height; - XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y, - icon_win_width, icon_win_height); - AdjustIconWindows(); - if (!(local_flags & HIDE_H) && diffx) - RedrawHScrollbar(); - if (!(local_flags & HIDE_V) && diffy) - RedrawVScrollbar(); - } - break; - case M_ICON_FILE: - case M_RES_CLASS: - UpdateItem(type, body[0], (char *)&body[3]); - break; - case M_WINDOW_NAME: - tmp = UpdateItem(type, body[0], (char *)&body[3]); - if (!ready || tmp == NULL) - break; - if (sortby == WINDOWNAME && tmp->IconWin != None - && desk_cond(tmp) && SortItem(tmp) == True) - AdjustIconWindows(); - break; - case M_RES_NAME: - if ((tmp = UpdateItem(type, body[0], (char *)&body[3])) == NULL) - break; - if (LookInList(tmp) && ready){ - if (sortby != UNSORT) - SortItem(tmp); - CreateIconWindow(tmp); - ConfigureIconWindow(tmp); - AdjustIconWindows(); - if (desk_cond(tmp)){ - if (max_icon_height != 0) - XMapWindow(dpy, tmp->icon_pixmap_w); - XMapWindow(dpy, tmp->IconWin); - if (!(local_flags & HIDE_H)) - RedrawHScrollbar(); - if (!(local_flags & HIDE_V)) - RedrawVScrollbar(); - } - } - break; - case M_ICON_NAME: - tmp = UpdateItem(type, body[0], (char *)&body[3]); - if (!ready || tmp == NULL) - break; - if (sortby != UNSORT && tmp->IconWin != None - && desk_cond(tmp) && SortItem(tmp) == True) - AdjustIconWindows(); - if (tmp->IconWin != None && desk_cond(tmp)) - RedrawIcon(tmp, 2); - break; - case M_DEFAULTICON: - str = (char *)safemalloc(strlen((char *)&body[3])+1); - strcpy(str, (char *)&body[3]); - FvwmDefaultIcon = str; - break; - case M_ICONIFY: - case M_DEICONIFY: - if (ready && (tmp = SetFlag(body[0], type)) != NULL) - RedrawIcon(tmp, 2); - break; - case M_FOCUS_CHANGE: - if (!ready) - break; - tmp = Head; - while(tmp != NULL){ - if (tmp->id == body[0]) break; - tmp = tmp->next; - } - old = Hilite; - Hilite = tmp; - if (old != NULL) - RedrawIcon(old, redraw_flag); - if (tmp != NULL) - RedrawIcon(tmp, redraw_flag); - break; - case M_NEW_DESK: - if (CurrentDesk != body[0]){ - CurrentDesk = body[0]; - if (body[0] != 10000 && ready){ /* 10000 is a "magic" number used in FvwmPager */ - if (sortby != UNSORT) - SortItem(NULL); - num_icons = AdjustIconWindows(); - GetIconwinSize(&diffx, &diffy); - icon_win_x = icon_win_y = 0; - if (primary == BOTTOM || secondary == BOTTOM) - icon_win_y = icon_win_height - Height; - if (primary == RIGHT || secondary == RIGHT) - icon_win_x = icon_win_width - Width; - XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y, - icon_win_width, icon_win_height); - XUnmapSubwindows(dpy, icon_win); - mapicons(); - if (!(local_flags & HIDE_H)) - RedrawHScrollbar(); - if (!(local_flags & HIDE_V)) - RedrawVScrollbar(); - } - } - break; - case M_END_WINDOWLIST: - GetIconwinSize(&diffx, &diffy); - tmp = Head; - while(tmp != NULL){ - CreateIconWindow(tmp); - ConfigureIconWindow(tmp); - tmp = tmp->next; - } - if (sortby != UNSORT) - SortItem(NULL); - if (primary == BOTTOM || secondary == BOTTOM) - icon_win_y = icon_win_height - Height; - if (primary == RIGHT || secondary == RIGHT) - icon_win_x = icon_win_width - Width; - XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y, - icon_win_width, icon_win_height); - AdjustIconWindows(); - XMapWindow(dpy,main_win); - XMapSubwindows(dpy, main_win); - XMapWindow(dpy, icon_win); - mapicons(); - ready = 1; - break; - default: - break; - } + struct icon_info *tmp, *old; + char *str; + long olddesk; + + switch (type) { + case M_CONFIGURE_WINDOW: + if (ready) { + if (!(local_flags & CURRENT_ONLY)) + break; + tmp = Head; + while (tmp != NULL) { + if (tmp->id == body[0]) { + if ((tmp->desk != body[7]) && + !(tmp->flags & STICKY)) { + olddesk = tmp->desk; + tmp->desk = body[7]; + if (olddesk == CurrentDesk || + tmp->desk == CurrentDesk) { + if (tmp->desk == + CurrentDesk && + sortby != UNSORT) + SortItem(NULL); + num_icons = + AdjustIconWindows(); + GetIconwinSize( + &diffx, &diffy); + if (diffy && + (primary == + BOTTOM || + secondary == + BOTTOM)) + icon_win_y += + diffy; + if (diffx && + (primary == RIGHT || + secondary == + RIGHT)) + icon_win_x += + diffx; + if (icon_win_y < 0) + icon_win_y = 0; + if (icon_win_x < 0) + icon_win_x = 0; + if (icon_win_x + Width > + icon_win_width) + icon_win_x = + icon_win_width - + Width; + if (icon_win_y + + Height > + icon_win_height) + icon_win_y = + icon_win_height - + Height; + XMoveResizeWindow(dpy, + icon_win, + -icon_win_x, + -icon_win_y, + icon_win_width, + icon_win_height); + if (tmp->desk == + CurrentDesk) { + XMapWindow(dpy, + tmp->IconWin); + if (max_icon_height != + 0) + XMapWindow( + dpy, + tmp->icon_pixmap_w); + } else { + XUnmapWindow( + dpy, + tmp->IconWin); + if (max_icon_height != + 0) + XUnmapWindow( + dpy, + tmp->icon_pixmap_w); + } + if (!(local_flags & + HIDE_H) && + diffx) + RedrawHScrollbar(); + if (!(local_flags & + HIDE_V) && + diffy) + RedrawVScrollbar(); + } + } else if ((body[8] & STICKY) && + !(tmp->flags & + STICKY)) /* stick */ + tmp->flags |= STICKY; + else if (!(body[8] & STICKY) && + (tmp->flags & + STICKY)) { /* unstick */ + tmp->flags &= ~STICKY; + tmp->desk = body[7]; + } + return; + } + tmp = tmp->next; + } + break; + } + case M_ADD_WINDOW: + if (AddItem(body[0], body[7], body[8]) == True && ready) { + GetIconwinSize(&diffx, &diffy); + if (diffy && (primary == BOTTOM || secondary == BOTTOM)) + icon_win_y += diffy; + if (diffx && (primary == RIGHT || secondary == RIGHT)) + icon_win_x += diffx; + XMoveResizeWindow(dpy, icon_win, -icon_win_x, + -icon_win_y, icon_win_width, icon_win_height); + } + break; + case M_DESTROY_WINDOW: + if (DeleteItem(body[0]) && ready) { + GetIconwinSize(&diffx, &diffy); + if (diffy && (primary == BOTTOM || secondary == BOTTOM)) + icon_win_y += diffy; + if (diffx && (primary == RIGHT || secondary == RIGHT)) + icon_win_x += diffx; + if (icon_win_y < 0) + icon_win_y = 0; + if (icon_win_x < 0) + icon_win_x = 0; + if (icon_win_x + Width > icon_win_width) + icon_win_x = icon_win_width - Width; + if (icon_win_y + Height > icon_win_height) + icon_win_y = icon_win_height - Height; + XMoveResizeWindow(dpy, icon_win, -icon_win_x, + -icon_win_y, icon_win_width, icon_win_height); + AdjustIconWindows(); + if (!(local_flags & HIDE_H) && diffx) + RedrawHScrollbar(); + if (!(local_flags & HIDE_V) && diffy) + RedrawVScrollbar(); + } + break; + case M_ICON_FILE: + case M_RES_CLASS: + UpdateItem(type, body[0], (char *)&body[3]); + break; + case M_WINDOW_NAME: + tmp = UpdateItem(type, body[0], (char *)&body[3]); + if (!ready || tmp == NULL) + break; + if (sortby == WINDOWNAME && tmp->IconWin != None && + desk_cond(tmp) && SortItem(tmp) == True) + AdjustIconWindows(); + break; + case M_RES_NAME: + if ((tmp = UpdateItem(type, body[0], (char *)&body[3])) == NULL) + break; + if (LookInList(tmp) && ready) { + if (sortby != UNSORT) + SortItem(tmp); + CreateIconWindow(tmp); + ConfigureIconWindow(tmp); + AdjustIconWindows(); + if (desk_cond(tmp)) { + if (max_icon_height != 0) + XMapWindow(dpy, tmp->icon_pixmap_w); + XMapWindow(dpy, tmp->IconWin); + if (!(local_flags & HIDE_H)) + RedrawHScrollbar(); + if (!(local_flags & HIDE_V)) + RedrawVScrollbar(); + } + } + break; + case M_ICON_NAME: + tmp = UpdateItem(type, body[0], (char *)&body[3]); + if (!ready || tmp == NULL) + break; + if (sortby != UNSORT && tmp->IconWin != None && + desk_cond(tmp) && SortItem(tmp) == True) + AdjustIconWindows(); + if (tmp->IconWin != None && desk_cond(tmp)) + RedrawIcon(tmp, 2); + break; + case M_DEFAULTICON: + str = (char *)xmalloc(strlen((char *)&body[3]) + 1); + strlcpy(str, (char *)&body[3], strlen((char *)&body[3]) + 1); + FvwmDefaultIcon = str; + break; + case M_ICONIFY: + case M_DEICONIFY: + if (ready && (tmp = SetFlag(body[0], type)) != NULL) + RedrawIcon(tmp, 2); + break; + case M_FOCUS_CHANGE: + if (!ready) + break; + tmp = Head; + while (tmp != NULL) { + if (tmp->id == body[0]) + break; + tmp = tmp->next; + } + old = Hilite; + Hilite = tmp; + if (old != NULL) + RedrawIcon(old, redraw_flag); + if (tmp != NULL) + RedrawIcon(tmp, redraw_flag); + break; + case M_NEW_DESK: + if (CurrentDesk != body[0]) { + CurrentDesk = body[0]; + if (body[0] != 10000 && + ready) { /* 10000 is a "magic" number used in + FvwmPager */ + if (sortby != UNSORT) + SortItem(NULL); + num_icons = AdjustIconWindows(); + GetIconwinSize(&diffx, &diffy); + icon_win_x = icon_win_y = 0; + if (primary == BOTTOM || secondary == BOTTOM) + icon_win_y = icon_win_height - Height; + if (primary == RIGHT || secondary == RIGHT) + icon_win_x = icon_win_width - Width; + XMoveResizeWindow(dpy, icon_win, -icon_win_x, + -icon_win_y, icon_win_width, + icon_win_height); + XUnmapSubwindows(dpy, icon_win); + mapicons(); + if (!(local_flags & HIDE_H)) + RedrawHScrollbar(); + if (!(local_flags & HIDE_V)) + RedrawVScrollbar(); + } + } + break; + case M_END_WINDOWLIST: + GetIconwinSize(&diffx, &diffy); + tmp = Head; + while (tmp != NULL) { + CreateIconWindow(tmp); + ConfigureIconWindow(tmp); + tmp = tmp->next; + } + if (sortby != UNSORT) + SortItem(NULL); + if (primary == BOTTOM || secondary == BOTTOM) + icon_win_y = icon_win_height - Height; + if (primary == RIGHT || secondary == RIGHT) + icon_win_x = icon_win_width - Width; + XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y, + icon_win_width, icon_win_height); + AdjustIconWindows(); + XMapWindow(dpy, main_win); + XMapSubwindows(dpy, main_win); + XMapWindow(dpy, icon_win); + mapicons(); + ready = 1; + break; + default: + break; + } } -struct icon_info *SetFlag(unsigned long id, int t) +struct icon_info * +SetFlag(unsigned long id, int t) { - struct icon_info *tmp; - tmp = Head; - - while(tmp != NULL){ - if (tmp->id == id){ - if (t == M_ICONIFY) - tmp->flags |= ICONIFIED; - else - tmp->flags ^= ICONIFIED; - return tmp; - } - tmp = tmp->next; - } - return NULL; + struct icon_info *tmp; + tmp = Head; + + while (tmp != NULL) { + if (tmp->id == id) { + if (t == M_ICONIFY) + tmp->flags |= ICONIFIED; + else + tmp->flags ^= ICONIFIED; + return tmp; + } + tmp = tmp->next; + } + return NULL; } -void mapicons(void) +void +mapicons(void) { - struct icon_info *tmp; - tmp = Head; - - while(tmp != NULL){ - if (desk_cond(tmp)){ - XMapWindow(dpy, tmp->IconWin); - if (max_icon_height != 0) - XMapWindow(dpy, tmp->icon_pixmap_w); - } - tmp = tmp->next; - } + struct icon_info *tmp; + tmp = Head; + + while (tmp != NULL) { + if (desk_cond(tmp)) { + XMapWindow(dpy, tmp->IconWin); + if (max_icon_height != 0) + XMapWindow(dpy, tmp->icon_pixmap_w); + } + tmp = tmp->next; + } } -int AdjustIconWindows(void) +int +AdjustIconWindows(void) { - struct icon_info *tmp; - int i = 0; - tmp = Head; - - while(tmp != NULL){ - if (desk_cond(tmp) && tmp->IconWin != None) - AdjustIconWindow(tmp, i++); - tmp = tmp->next; - } - return i; + struct icon_info *tmp; + int i = 0; + tmp = Head; + + while (tmp != NULL) { + if (desk_cond(tmp) && tmp->IconWin != None) + AdjustIconWindow(tmp, i++); + tmp = tmp->next; + } + return i; } -int desk_cond(struct icon_info *item) +int +desk_cond(struct icon_info *item) { - if (!(local_flags & CURRENT_ONLY) || - (item->flags & STICKY) || (item->desk == CurrentDesk)) - return 1; + if (!(local_flags & CURRENT_ONLY) || (item->flags & STICKY) || + (item->desk == CurrentDesk)) + return 1; - return 0; + return 0; } /************************************************************************ @@ -2096,64 +2286,66 @@ int desk_cond(struct icon_info *item) * Skeleton based on AddItem() from FvwmWinList: * Copyright 1994, Mike Finger. ***********************************************************************/ -Bool AddItem(unsigned long id, long desk, unsigned long flags) +Bool +AddItem(unsigned long id, long desk, unsigned long flags) { - struct icon_info *new, *tmp; - tmp = Head; - - if (id == main_win || (flags & TRANSIENT) || !(flags & SUPPRESSICON)) - return False; + struct icon_info *new, *tmp; + tmp = Head; + + if (id == main_win || (flags & TRANSIENT) || !(flags & SUPPRESSICON)) + return False; + + while (tmp != NULL) { + if (tmp->id == id || + (tmp->wmhints && (tmp->wmhints->flags & IconWindowHint) && + tmp->wmhints->icon_window == id)) + return False; + tmp = tmp->next; + } - while (tmp != NULL){ - if (tmp->id == id || - (tmp->wmhints && (tmp->wmhints->flags & IconWindowHint) && - tmp->wmhints->icon_window == id)) - return False; - tmp = tmp->next; - } + new = (struct icon_info *)xmalloc(sizeof(struct icon_info)); + new->name = NULL; + new->window_name = NULL; + new->res_class = NULL; + new->res_name = NULL; + new->action = NULL; + new->icon_file = NULL; + new->icon_w = 0; + new->icon_h = 0; + new->IconWin = None; + new->iconPixmap = None; + new->icon_maskPixmap = None; + new->icon_pixmap_w = None; + new->icon_depth = 0; + new->desk = desk; + new->id = id; + new->extra_flags = DEFAULTICON; + new->flags = flags | ICON_OURS; + new->wmhints = NULL; + + /* add new item to the head of the list + + new->prev = NULL; + new->next = Head; + if (Head != NULL) + Head->prev = new; + else + Tail = new; + Head = new; */ + + /* add new item to the tail of the list */ + new->prev = Tail; + new->next = NULL; + if (Tail != NULL) + Tail->next = new; + else + Head = new; + Tail = new; + + if (desk_cond(new)) + num_icons++; - new = (struct icon_info *)safemalloc(sizeof(struct icon_info)); - new->name = NULL; - new->window_name = NULL; - new->res_class = NULL; - new->res_name = NULL; - new->action = NULL; - new->icon_file = NULL; - new->icon_w = 0; - new->icon_h = 0; - new->IconWin = None; - new->iconPixmap = None; - new->icon_maskPixmap = None; - new->icon_pixmap_w = None; - new->icon_depth = 0; - new->desk = desk; - new->id = id; - new->extra_flags = DEFAULTICON; - new->flags = flags | ICON_OURS; - new->wmhints = NULL; - -/* add new item to the head of the list - - new->prev = NULL; - new->next = Head; - if (Head != NULL) - Head->prev = new; - else - Tail = new; - Head = new; */ - -/* add new item to the tail of the list */ - new->prev = Tail; - new->next = NULL; - if (Tail != NULL) - Tail->next = new; - else - Head = new; - Tail = new; - - if (desk_cond(new)) num_icons++; - - return True; + return True; } /************************************************************************ @@ -2161,39 +2353,41 @@ Bool AddItem(unsigned long id, long desk, unsigned long flags) * Skeleton based on DeleteItem() from FvwmWinList: * Copyright 1994, Mike Finger. ***********************************************************************/ -Bool DeleteItem(unsigned long id) +Bool +DeleteItem(unsigned long id) { - struct icon_info *tmp = Head; - - while(tmp != NULL){ - if (tmp->id == id){ - if (desk_cond(tmp)) - num_icons--; - if (Hilite == tmp) - Hilite = NULL; - if ((tmp->icon_pixmap_w != None) && (tmp->flags & ICON_OURS)) - XDestroyWindow(dpy, tmp->icon_pixmap_w); - if (tmp->IconWin != None) - XDestroyWindow(dpy, tmp->IconWin); - if (tmp == Head){ - Head = tmp->next; - if (Head != NULL) - Head->prev = NULL; - else - Tail = NULL; - }else { - if (Tail == tmp) - Tail = tmp->prev; - tmp->prev->next = tmp->next; - if (tmp->next != NULL) - tmp->next->prev = tmp->prev; - } - freeitem(tmp, 1); - return True; - } - tmp = tmp->next; - } - return False; + struct icon_info *tmp = Head; + + while (tmp != NULL) { + if (tmp->id == id) { + if (desk_cond(tmp)) + num_icons--; + if (Hilite == tmp) + Hilite = NULL; + if ((tmp->icon_pixmap_w != None) && + (tmp->flags & ICON_OURS)) + XDestroyWindow(dpy, tmp->icon_pixmap_w); + if (tmp->IconWin != None) + XDestroyWindow(dpy, tmp->IconWin); + if (tmp == Head) { + Head = tmp->next; + if (Head != NULL) + Head->prev = NULL; + else + Tail = NULL; + } else { + if (Tail == tmp) + Tail = tmp->prev; + tmp->prev->next = tmp->next; + if (tmp->next != NULL) + tmp->next->prev = tmp->prev; + } + freeitem(tmp, 1); + return True; + } + tmp = tmp->next; + } + return False; } /************************************************************************ @@ -2201,184 +2395,192 @@ Bool DeleteItem(unsigned long id) * Skeleton based on UpdateItem() from FvwmWinList: * Copyright 1994, Mike Finger. ***********************************************************************/ -struct icon_info *UpdateItem(unsigned long type, unsigned long id, char *item) +struct icon_info * +UpdateItem(unsigned long type, unsigned long id, char *item) { - struct icon_info *tmp; - char *str; - XClassHint classhint; - int ret; - - tmp = Head; - while (tmp != NULL){ - if (tmp->id == id){ - str = (char *)safemalloc(strlen(item)+1); - strcpy(str, item); - - switch (type){ - case M_ICON_NAME: - if (tmp->name != NULL) - free(tmp->name); - tmp->name = str; - return tmp; - case M_ICON_FILE: - tmp->icon_file = str; - tmp->extra_flags &= ~DEFAULTICON; - return tmp; - case M_WINDOW_NAME: - if (tmp->window_name != NULL) - free(tmp->window_name); - tmp->window_name = str; - return tmp; - case M_RES_CLASS: - tmp->res_class = str; - ret = 0; - if (sortby == RESCLASS && strcmp(NoClass, str) == 0 - && !(ret = XGetClassHint(dpy, tmp->id, &classhint))){ - tmp->extra_flags |= NOCLASS; - } - if (ret){ - if (classhint.res_class != NULL) - XFree(classhint.res_class); - if (classhint.res_name != NULL) - XFree(classhint.res_name); - } - return tmp; - case M_RES_NAME: - tmp->res_name = str; - ret = 0; - if (sortby == RESNAME && strcmp(NoResource, str) == 0 - && !(ret = XGetClassHint(dpy, tmp->id, &classhint))) - tmp->extra_flags |= NONAME; - if (ret){ - if (classhint.res_class != NULL) - XFree(classhint.res_class); - if (classhint.res_name != NULL) - XFree(classhint.res_name); - } - return tmp; - } - } - tmp = tmp->next; - } - return NULL; + struct icon_info *tmp; + char *str; + XClassHint classhint; + int ret; + + tmp = Head; + while (tmp != NULL) { + if (tmp->id == id) { + size_t item_len = strlen(item) + 1; + str = (char *)xmalloc(item_len); + strlcpy(str, item, item_len); + + switch (type) { + case M_ICON_NAME: + if (tmp->name != NULL) + free(tmp->name); + tmp->name = str; + return tmp; + case M_ICON_FILE: + tmp->icon_file = str; + tmp->extra_flags &= ~DEFAULTICON; + return tmp; + case M_WINDOW_NAME: + if (tmp->window_name != NULL) + free(tmp->window_name); + tmp->window_name = str; + return tmp; + case M_RES_CLASS: + tmp->res_class = str; + ret = 0; + if (sortby == RESCLASS && + strcmp(NoClass, str) == 0 && + !(ret = XGetClassHint( + dpy, tmp->id, &classhint))) { + tmp->extra_flags |= NOCLASS; + } + if (ret) { + if (classhint.res_class != NULL) + XFree(classhint.res_class); + if (classhint.res_name != NULL) + XFree(classhint.res_name); + } + return tmp; + case M_RES_NAME: + tmp->res_name = str; + ret = 0; + if (sortby == RESNAME && + strcmp(NoResource, str) == 0 && + !(ret = XGetClassHint( + dpy, tmp->id, &classhint))) + tmp->extra_flags |= NONAME; + if (ret) { + if (classhint.res_class != NULL) + XFree(classhint.res_class); + if (classhint.res_name != NULL) + XFree(classhint.res_name); + } + return tmp; + } + } + tmp = tmp->next; + } + return NULL; } -Bool SortItem(struct icon_info *item) +Bool +SortItem(struct icon_info *item) { - struct icon_info *tmp1=Head, *a, *b, *tmp2; - - if (tmp1 == NULL) - return False; - - if (item != NULL && - ((itemcmp(item->prev, item) <= 0) && - (itemcmp(item->next, item) >= 0))) - return False; - - while (tmp1->next != NULL){ - tmp2 = MinItem(tmp1); - if (tmp1 == tmp2){ - tmp1 = tmp1->next; - continue; - } - if (tmp1 == Head) - Head = tmp2; - a = tmp1->prev; - b = tmp1->next; - if (tmp1->prev != NULL) - tmp1->prev->next = tmp2; - if (b != tmp2) - tmp1->next->prev = tmp2; - if (b != tmp2) - tmp2->prev->next = tmp1; - if (tmp2->next != NULL) - tmp2->next->prev = tmp1; - if (b == tmp2){ - tmp1->prev = tmp2; - tmp1->next = tmp2->next; - tmp2->prev = a; - tmp2->next = tmp1; - }else{ - tmp1->prev = tmp2->prev; - tmp1->next = tmp2->next; - tmp2->prev = a; - tmp2->next = b; - } - tmp1 = b; - } - Tail = tmp1; + struct icon_info *tmp1 = Head, *a, *b, *tmp2; + + if (tmp1 == NULL) + return False; + + if (item != NULL && ((itemcmp(item->prev, item) <= 0) && + (itemcmp(item->next, item) >= 0))) + return False; - return True; + while (tmp1->next != NULL) { + tmp2 = MinItem(tmp1); + if (tmp1 == tmp2) { + tmp1 = tmp1->next; + continue; + } + if (tmp1 == Head) + Head = tmp2; + a = tmp1->prev; + b = tmp1->next; + if (tmp1->prev != NULL) + tmp1->prev->next = tmp2; + if (b != tmp2) + tmp1->next->prev = tmp2; + if (b != tmp2) + tmp2->prev->next = tmp1; + if (tmp2->next != NULL) + tmp2->next->prev = tmp1; + if (b == tmp2) { + tmp1->prev = tmp2; + tmp1->next = tmp2->next; + tmp2->prev = a; + tmp2->next = tmp1; + } else { + tmp1->prev = tmp2->prev; + tmp1->next = tmp2->next; + tmp2->prev = a; + tmp2->next = b; + } + tmp1 = b; + } + Tail = tmp1; + + return True; } -struct icon_info *MinItem(struct icon_info *head) +struct icon_info * +MinItem(struct icon_info *head) { - struct icon_info *tmp, *i_min; + struct icon_info *tmp, *i_min; - if (head == NULL) - return NULL; + if (head == NULL) + return NULL; - i_min = head; - tmp = head->next; - while (tmp != NULL){ - if (itemcmp(i_min, tmp) > 0) - i_min = tmp; - tmp = tmp->next; - } - return i_min; + i_min = head; + tmp = head->next; + while (tmp != NULL) { + if (itemcmp(i_min, tmp) > 0) + i_min = tmp; + tmp = tmp->next; + } + return i_min; } -int itemcmp(struct icon_info *item1, struct icon_info *item2) +int +itemcmp(struct icon_info *item1, struct icon_info *item2) { - int ret1, ret2; - - if (item1 == NULL){ - if (item2 == NULL) - return 0; - else - return -1; - } else if (item2 == NULL) - return 1; - - /* skip items not on the current desk */ - ret1 = desk_cond(item1); - ret2 = desk_cond(item2); - if (!ret1 || !ret2) - return (ret1 - ret2); - - ret1 = 0; - ret2 = strcmp(item1->name, item2->name); - - switch(sortby){ - case WINDOWNAME: - ret1 = strcmp(item1->window_name, item2->window_name); - break; - case RESCLASS: - if ((item1->extra_flags & NOCLASS)){ - if ((item2->extra_flags & NOCLASS)) - ret1 = 0; - else if (!(item2->extra_flags & NOCLASS)) - ret1 = -1; - }else if ((item2->extra_flags & NOCLASS)) - ret1 = 1; - else - ret1 = strcmp(item1->res_class, item2->res_class); - break; - case RESNAME: - if ((item1->extra_flags & NOCLASS)){ - if ((item2->extra_flags & NOCLASS)) - ret1 = 0; - else if (!(item2->extra_flags & NOCLASS)) - ret1 = -1; - }else if ((item2->extra_flags & NOCLASS)) - ret1 = 1; - else - ret1 = strcmp(item1->res_name, item2->res_name); - break; - default: - break; - } - return (ret1 != 0 ? ret1 : ret2); + int ret1, ret2; + + if (item1 == NULL) { + if (item2 == NULL) + return 0; + else + return -1; + } else if (item2 == NULL) + return 1; + + /* skip items not on the current desk */ + ret1 = desk_cond(item1); + ret2 = desk_cond(item2); + if (!ret1 || !ret2) + return (ret1 - ret2); + + ret1 = 0; + ret2 = strcmp(item1->name, item2->name); + + switch (sortby) { + case WINDOWNAME: + ret1 = strcmp(item1->window_name, item2->window_name); + break; + case RESCLASS: + if ((item1->extra_flags & NOCLASS)) { + if ((item2->extra_flags & NOCLASS)) + ret1 = 0; + else if (!(item2->extra_flags & NOCLASS)) + ret1 = -1; + } else if ((item2->extra_flags & NOCLASS)) + ret1 = 1; + else + ret1 = strcmp(item1->res_class, item2->res_class); + break; + case RESNAME: + if ((item1->extra_flags & NOCLASS)) { + if ((item2->extra_flags & NOCLASS)) + ret1 = 0; + else if (!(item2->extra_flags & NOCLASS)) + ret1 = -1; + } else if ((item2->extra_flags & NOCLASS)) + ret1 = 1; + else + ret1 = strcmp(item1->res_name, item2->res_name); + break; + default: + break; + } + return (ret1 != 0 ? ret1 : ret2); } /* @@ -2390,9 +2592,9 @@ void ShowItem(struct icon_info *head) tmp = head; while (tmp != NULL){ fprintf(stderr, "id:%x name:%s resname:%s class%s iconfile:%s\n", - tmp->id, - tmp->name == NULL ? "NULL" : tmp->name, tmp->res_name, - tmp->res_class, tmp->icon_file); + tmp->id, + tmp->name == NULL ? "NULL" : tmp->name, tmp->res_name, + tmp->res_class, tmp->icon_file); tmp = tmp->next; } } @@ -2404,7 +2606,7 @@ void ShowAction(void) tmp = MouseActions; while (tmp != NULL){ fprintf(stderr, "mouse:%d type %d action:%s\n", tmp->mouse, - tmp->type, tmp->action); + tmp->type, tmp->action); tmp = tmp->next; } } @@ -2416,246 +2618,262 @@ void ShowKAction(void) tmp = KeyActions; while (tmp != NULL){ fprintf(stderr, "key:%s keycode:%d action:%s\n", tmp->name, - tmp->keycode, tmp->action); + tmp->keycode, tmp->action); tmp = tmp->next; } } */ -void freeitem(struct icon_info *item, int d) +void +freeitem(struct icon_info *item, int d) { - if (item == NULL) - return; - - if (!(item->flags & ICON_OURS)){ - if (max_icon_height != 0) - XUnmapWindow(dpy, item->icon_pixmap_w); - if (d == 0) - XReparentWindow(dpy, item->icon_pixmap_w, Root, 0, 0); - } + if (item == NULL) + return; - if (item->name != NULL) - free(item->name); - if (item->window_name != NULL) - free(item->window_name); - if (item->res_name != NULL) - free(item->res_name); - if (item->res_class != NULL) - free(item->res_class); - if (item->wmhints != NULL) - XFree(item->wmhints); - if (item->iconPixmap != None) - XFreePixmap(dpy, item->iconPixmap); - if (item->icon_maskPixmap != None && - (item->wmhints == NULL || - !(item->wmhints->flags & (IconPixmapHint|IconWindowHint)))) - XFreePixmap(dpy, item->icon_maskPixmap); - - free(item); -} + if (!(item->flags & ICON_OURS)) { + if (max_icon_height != 0) + XUnmapWindow(dpy, item->icon_pixmap_w); + if (d == 0) + XReparentWindow(dpy, item->icon_pixmap_w, Root, 0, 0); + } + if (item->name != NULL) + free(item->name); + if (item->window_name != NULL) + free(item->window_name); + if (item->res_name != NULL) + free(item->res_name); + if (item->res_class != NULL) + free(item->res_class); + if (item->wmhints != NULL) + XFree(item->wmhints); + if (item->iconPixmap != None) + XFreePixmap(dpy, item->iconPixmap); + if (item->icon_maskPixmap != None && + (item->wmhints == NULL || + !(item->wmhints->flags & (IconPixmapHint | IconWindowHint)))) + XFreePixmap(dpy, item->icon_maskPixmap); + + free(item); +} /************************************************************************ IsClick - Based on functions.c from Fvwm: - Copyright 1988, Evans and Sutherland Computer Corporation, - Copyright 1989, Massachusetts Institute of Technology, - Copyright 1993, Robert Nation. + Based on functions.c from Fvwm: + Copyright 1988, Evans and Sutherland Computer Corporation, + Copyright 1989, Massachusetts Institute of Technology, + Copyright 1993, Robert Nation. ***********************************************************************/ -Bool IsClick(int x,int y,unsigned EndMask, XEvent *d) +Bool +IsClick(int x, int y, unsigned EndMask, XEvent *d) { - int xcurrent,ycurrent,total = 0; - - xcurrent = x; - ycurrent = y; - while((total < ClickTime)&& - (x - xcurrent < 5)&&(x - xcurrent > -5)&& - (y - ycurrent < 5)&&(y - ycurrent > -5)) - { - usleep(10000); - total+=10; - if(XCheckMaskEvent (dpy,EndMask, d)) - return True; - if(XCheckMaskEvent (dpy,ButtonMotionMask|PointerMotionMask, d)) - { - xcurrent = d->xmotion.x_root; - ycurrent = d->xmotion.y_root; - } - } - return False; + int xcurrent, ycurrent, total = 0; + + xcurrent = x; + ycurrent = y; + while ((total < ClickTime) && (x - xcurrent < 5) && + (x - xcurrent > -5) && (y - ycurrent < 5) && + (y - ycurrent > -5)) { + usleep(10000); + total += 10; + if (XCheckMaskEvent(dpy, EndMask, d)) + return True; + if (XCheckMaskEvent( + dpy, ButtonMotionMask | PointerMotionMask, d)) { + xcurrent = d->xmotion.x_root; + ycurrent = d->xmotion.y_root; + } + } + return False; } /************************************************************************ * ExecuteAction * Based on part of ComplexFunction() of functions.c from fvwm: - Copyright 1988, Evans and Sutherland Computer Corporation, - Copyright 1989, Massachusetts Institute of Technology, - Copyright 1993, Robert Nation. + Copyright 1988, Evans and Sutherland Computer Corporation, + Copyright 1989, Massachusetts Institute of Technology, + Copyright 1993, Robert Nation. ***********************************************************************/ -void ExecuteAction(int x, int y, struct icon_info *item) +void +ExecuteAction(int x, int y, struct icon_info *item) { - int type = NO_CLICK; - XEvent *ev; - XEvent d; - struct mousefunc *tmp; + int type = NO_CLICK; + XEvent *ev; + XEvent d; + struct mousefunc *tmp; + + /* Wait and see if we have a click, or a move */ + /* wait 100 msec, see if the used releases the button */ + if (IsClick(x, y, ButtonReleaseMask, &d)) { + type = CLICK; + ev = &d; + } - /* Wait and see if we have a click, or a move */ - /* wait 100 msec, see if the used releases the button */ - if(IsClick(x,y,ButtonReleaseMask,&d)) - { - type = CLICK; - ev = &d; - } - - /* If it was a click, wait to see if its a double click */ - if((type == CLICK) && (IsClick(x,y,ButtonPressMask, &d))) - { - type = ONE_AND_A_HALF_CLICKS; - ev = &d; - } - if((type == ONE_AND_A_HALF_CLICKS) && - (IsClick(x,y,ButtonReleaseMask, &d))) - { - type = DOUBLE_CLICK; - ev = &d; - } - tmp = MouseActions; + /* If it was a click, wait to see if its a double click */ + if ((type == CLICK) && (IsClick(x, y, ButtonPressMask, &d))) { + type = ONE_AND_A_HALF_CLICKS; + ev = &d; + } + if ((type == ONE_AND_A_HALF_CLICKS) && + (IsClick(x, y, ButtonReleaseMask, &d))) { + type = DOUBLE_CLICK; + ev = &d; + } + tmp = MouseActions; - while (tmp != NULL){ - if (tmp->mouse == d.xbutton.button && tmp->type == type){ - SendFvwmPipe(fd, tmp->action, item->id); - return; - } - tmp = tmp->next; - } + while (tmp != NULL) { + if (tmp->mouse == d.xbutton.button && tmp->type == type) { + SendFvwmPipe(fd, tmp->action, item->id); + return; + } + tmp = tmp->next; + } } -void ExecuteKey(XEvent event) +void +ExecuteKey(XEvent event) { - struct icon_info *item; - struct keyfunc *tmp; + struct icon_info *item; + struct keyfunc *tmp; - if ((item = Hilite) == NULL) - if ((item = Head) == NULL) - return; + if ((item = Hilite) == NULL) + if ((item = Head) == NULL) + return; - tmp = KeyActions; - event.xkey.keycode = - XKeysymToKeycode(dpy,XKeycodeToKeysym(dpy,event.xkey.keycode,0)); - while (tmp != NULL){ - if (tmp->keycode == event.xkey.keycode){ - SendFvwmPipe(fd, tmp->action, item->id); - return; - } - tmp = tmp->next; - } + tmp = KeyActions; + { + KeySym *mapping; + int width; + + mapping = + XGetKeyboardMapping(dpy, event.xkey.keycode, 1, &width); + if (mapping != NULL) { + KeySym primary = width > 0 ? mapping[0] : NoSymbol; + KeyCode canonical = (primary != NoSymbol) ? + XKeysymToKeycode(dpy, primary) : + 0; + if (canonical != 0) + event.xkey.keycode = canonical; + XFree(mapping); + } + } + while (tmp != NULL) { + if (tmp->keycode == event.xkey.keycode) { + SendFvwmPipe(fd, tmp->action, item->id); + return; + } + tmp = tmp->next; + } } /*********************************************************************** LookInList - Based on part of LookInList() of add_window.c from fvwm: - Copyright 1988, Evans and Sutherland Computer Corporation, - Copyright 1989, Massachusetts Institute of Technology, - Copyright 1993, Robert Nation. + Based on part of LookInList() of add_window.c from fvwm: + Copyright 1988, Evans and Sutherland Computer Corporation, + Copyright 1989, Massachusetts Institute of Technology, + Copyright 1993, Robert Nation. ***********************************************************************/ -int LookInList(struct icon_info *item) +int +LookInList(struct icon_info *item) { - int isdefault=1; - char *value=NULL; - struct iconfile *nptr; - - if (IconListHead == NULL) { - if ((item->extra_flags & DEFAULTICON) && (FvwmDefaultIcon != NULL)) - item->icon_file = FvwmDefaultIcon; - return 1; - } - + int isdefault = 1; + char *value = NULL; + struct iconfile *nptr; + + if (IconListHead == NULL) { + if ((item->extra_flags & DEFAULTICON) && + (FvwmDefaultIcon != NULL)) + item->icon_file = FvwmDefaultIcon; + return 1; + } - for (nptr = IconListHead; nptr != NULL; nptr = nptr->next){ - if (nptr == DefaultIcon) - isdefault = 1; + for (nptr = IconListHead; nptr != NULL; nptr = nptr->next) { + if (nptr == DefaultIcon) + isdefault = 1; - if (matchWildcards(nptr->name, item->res_class) == TRUE){ - value = nptr->iconfile; - if (nptr != DefaultIcon) - isdefault = 0; - } + if (matchWildcards(nptr->name, item->res_class) == TRUE) { + value = nptr->iconfile; + if (nptr != DefaultIcon) + isdefault = 0; + } - if (matchWildcards(nptr->name, item->res_name) == TRUE){ - value = nptr->iconfile; - if (nptr != DefaultIcon) - isdefault = 0; - } + if (matchWildcards(nptr->name, item->res_name) == TRUE) { + value = nptr->iconfile; + if (nptr != DefaultIcon) + isdefault = 0; + } - if (matchWildcards(nptr->name, item->window_name) == TRUE){ - value = nptr->iconfile; - if (nptr != DefaultIcon) - isdefault = 0; - } - } + if (matchWildcards(nptr->name, item->window_name) == TRUE) { + value = nptr->iconfile; + if (nptr != DefaultIcon) + isdefault = 0; + } + } - if (!isdefault){ - item->icon_file = value; - item->extra_flags &= ~DEFAULTICON; - }else if ((item->extra_flags & DEFAULTICON)){ - if (DefaultIcon != NULL) - item->icon_file = DefaultIcon->iconfile; - else if (FvwmDefaultIcon != NULL) - item->icon_file = FvwmDefaultIcon; - } + if (!isdefault) { + item->icon_file = value; + item->extra_flags &= ~DEFAULTICON; + } else if ((item->extra_flags & DEFAULTICON)) { + if (DefaultIcon != NULL) + item->icon_file = DefaultIcon->iconfile; + else if (FvwmDefaultIcon != NULL) + item->icon_file = FvwmDefaultIcon; + } - /* Icon is not shown if "-" is specified */ - if (item->icon_file != NULL && (strcmp(item->icon_file, "-") == 0)){ - DeleteItem(item->id); - return 0; - } - return 1; + /* Icon is not shown if "-" is specified */ + if (item->icon_file != NULL && (strcmp(item->icon_file, "-") == 0)) { + DeleteItem(item->id); + return 0; + } + return 1; } /*********************************************************************** strcpy - Based on stripcpy2() of configure.c from Fvwm: - Copyright 1988, Evans and Sutherland Computer Corporation, - Copyright 1989, Massachusetts Institute of Technology, - Copyright 1993, Robert Nation. + Based on stripcpy2() of configure.c from Fvwm: + Copyright 1988, Evans and Sutherland Computer Corporation, + Copyright 1989, Massachusetts Institute of Technology, + Copyright 1993, Robert Nation. ***********************************************************************/ -char *stripcpy2(char *source) +char * +stripcpy2(char *source) { - char *ptr; - int count = 0; - while((*source != '"')&&(*source != 0)) - source++; - if(*source == 0) - return 0; - - source++; - ptr = source; - while((*ptr!='"')&&(*ptr != 0)){ - ptr++; - count++; - } - ptr = safemalloc(count+1); - strncpy(ptr,source,count); - ptr[count]=0; - return ptr; + char *ptr; + int count = 0; + while ((*source != '"') && (*source != 0)) + source++; + if (*source == 0) + return 0; + + source++; + ptr = source; + while ((*ptr != '"') && (*ptr != 0)) { + ptr++; + count++; + } + ptr = xmalloc(count + 1); + strncpy(ptr, source, count); + ptr[count] = 0; + return ptr; } /*********************************************************************** Error handler ***********************************************************************/ -XErrorHandler myErrorHandler(Display *dpy, XErrorEvent *event) +XErrorHandler +myErrorHandler(Display *dpy, XErrorEvent *event) { - char msg[256]; + char msg[256]; - if (event->error_code == BadWindow) - return 0; + if (event->error_code == BadWindow) + return 0; - XGetErrorText(dpy, event->error_code, msg, 256); + XGetErrorText(dpy, event->error_code, msg, 256); - fprintf(stderr, "Error in %s: %s \n", MyName, msg); - fprintf(stderr, "Major opcode of failed request: %d \n", - event->request_code); - fprintf(stderr, "Resource id of failed request: 0x%lx \n", - event->resourceid); - return 0; + fprintf(stderr, "Error in %s: %s \n", MyName, msg); + fprintf(stderr, "Major opcode of failed request: %d \n", + event->request_code); + fprintf(stderr, "Resource id of failed request: 0x%lx \n", + event->resourceid); + return 0; } Index: fvwm/modules/FvwmIconBox/FvwmIconBox.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconBox/FvwmIconBox.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconBox/FvwmIconBox.h --- fvwm/modules/FvwmIconBox/FvwmIconBox.h +++ fvwm/modules/FvwmIconBox/FvwmIconBox.h @@ -6,32 +6,33 @@ #include "../../libs/fvwmlib.h" struct icon_info; Bool ExecIconBoxFunction(char *msg); -extern void CreateWindow(void); -extern Pixel GetColor(char *name); -extern Pixel GetHilite(Pixel background); -extern Pixel GetShadow(Pixel background); -extern void nocolor(char *a, char *b); -extern void RedrawWindow(void); -extern void match_string(char *tline); -extern void Loop(void); -extern void ParseOptions(void); -extern char *safemalloc(int length); -extern int My_XNextEvent(Display *dpy, XEvent *event); -extern void CopyString(char **dest, char *source); -extern void RelieveWindow(Window win,int x,int y,int w,int h,GC rGC,GC sGC); -extern void SendFvwmPipe(int *,char *text, unsigned long window); -extern void DeadPipe(int nonsense); -extern void CreateIconWindow(struct icon_info *item); -extern void ConfigureIconWindow(struct icon_info *item); -extern void DrawIconWindow(struct icon_info *item); -extern void GetBitmapFile(struct icon_info *item); -extern void GetXPMFile(struct icon_info *item); +extern void CreateWindow(void); +extern Pixel GetColor(char *name); +extern Pixel GetHilite(Pixel background); +extern Pixel GetShadow(Pixel background); +extern void nocolor(char *a, char *b); +extern void RedrawWindow(void); +extern void match_string(char *tline); +extern void Loop(void); +extern void ParseOptions(void); +extern int My_XNextEvent(Display *dpy, XEvent *event); +extern void CopyString(char **dest, char *source); +extern void RelieveWindow( + Window win, int x, int y, int w, int h, GC rGC, GC sGC); +extern void SendFvwmPipe(int *, char *text, unsigned long window); +extern void DeadPipe(int nonsense); +extern void CreateIconWindow(struct icon_info *item); +extern void ConfigureIconWindow(struct icon_info *item); +extern void DrawIconWindow(struct icon_info *item); +extern void GetBitmapFile(struct icon_info *item); +extern void GetXPMFile(struct icon_info *item); extern void GetIconWindow(struct icon_info *item); extern void GetIconBitmap(struct icon_info *item); -extern void process_message(unsigned long type,unsigned long *body); +extern void process_message(unsigned long type, unsigned long *body); extern Bool AddItem(unsigned long id, long desk, unsigned long flags); extern Bool DeleteItem(unsigned long id); -extern struct icon_info *UpdateItem(unsigned long type, unsigned long id, char *item); +extern struct icon_info *UpdateItem( + unsigned long type, unsigned long id, char *item); extern void freeitem(struct icon_info *item, int d); extern void RedrawHScrollbar(void); extern void RedrawVScrollbar(void); @@ -70,8 +71,7 @@ extern int desk_cond(struct icon_info *item); extern int itemcmp(struct icon_info *item1, struct icon_info *item2); extern XErrorHandler myErrorHandler(Display *dpy, XErrorEvent *event); - -extern Display *dpy; /* which display are we talking to */ +extern Display *dpy; /* which display are we talking to */ extern Window Root; extern Window main_win; extern Window holder_win; @@ -79,9 +79,9 @@ extern Window icon_win; extern int screen; extern int d_depth; extern Pixel fore_pix, back_pix, icon_fore_pix, icon_back_pix; -extern GC NormalGC; -extern GC ReliefGC; -extern int ButtonWidth,ButtonHeight; +extern GC NormalGC; +extern GC ReliefGC; +extern int ButtonWidth, ButtonHeight; extern XFontStruct *font; extern int num_rows; extern int num_columns; @@ -94,53 +94,49 @@ extern int icon_win_width, icon_win_height; extern Pixmap IconwinPixmap; extern char *IconwinPixmapFile; -struct icon_info -{ - char *action; - char *name; - char *window_name; - char *res_class; - char *res_name; - char *icon_file; - int x; - int y; - int icon_w; - int icon_h; - Pixmap iconPixmap; /* pixmap for the icon */ - Pixmap icon_maskPixmap; - Window IconWin; - Window icon_pixmap_w; - XWMHints *wmhints; - int icon_depth; - long id; - long desk; - long flags; - long extra_flags; - struct icon_info *next; - struct icon_info *prev; +struct icon_info { + char *action; + char *name; + char *window_name; + char *res_class; + char *res_name; + char *icon_file; + int x; + int y; + int icon_w; + int icon_h; + Pixmap iconPixmap; /* pixmap for the icon */ + Pixmap icon_maskPixmap; + Window IconWin; + Window icon_pixmap_w; + XWMHints *wmhints; + int icon_depth; + long id; + long desk; + long flags; + long extra_flags; + struct icon_info *next; + struct icon_info *prev; }; -struct iconfile -{ - char *name; - char *iconfile; - struct iconfile *next; +struct iconfile { + char *name; + char *iconfile; + struct iconfile *next; }; -struct mousefunc -{ - int mouse; - int type; - char *action; - struct mousefunc *next; +struct mousefunc { + int mouse; + int type; + char *action; + struct mousefunc *next; }; -struct keyfunc -{ - char *name; - KeyCode keycode; - char *action; - struct keyfunc *next; +struct keyfunc { + char *name; + KeyCode keycode; + char *action; + struct keyfunc *next; }; extern struct icon_info *Head; @@ -154,8 +150,6 @@ extern char *pixmapPath; extern int icon_relief; - - #define NOPLACE -1 #define LEFT 0 #define RIGHT 1 @@ -170,19 +164,18 @@ extern int icon_relief; #define DOUBLE_CLICK 2 /* sorting */ -#define UNSORT 0 +#define UNSORT 0 #define WINDOWNAME 1 -#define ICONNAME 2 -#define RESNAME 3 -#define RESCLASS 4 +#define ICONNAME 2 +#define RESNAME 3 +#define RESCLASS 4 /* local flags */ -#define HIDE_H (1<<0) -#define HIDE_V (1<<1) -#define SETWMICONSIZE (1<<2) -#define CURRENT_ONLY (1<<3) - -#define DEFAULTICON (1<<0) -#define NONAME (1<<1) -#define NOCLASS (1<<2) - +#define HIDE_H (1 << 0) +#define HIDE_V (1 << 1) +#define SETWMICONSIZE (1 << 2) +#define CURRENT_ONLY (1 << 3) + +#define DEFAULTICON (1 << 0) +#define NONAME (1 << 1) +#define NOCLASS (1 << 2) Index: fvwm/modules/FvwmIconBox/icons.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconBox/icons.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconBox/icons.c --- fvwm/modules/FvwmIconBox/icons.c +++ fvwm/modules/FvwmIconBox/icons.c @@ -9,28 +9,25 @@ * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ - /*********************************************************************** * * Derived from fvwm icon code * ***********************************************************************/ -#include "config.h" - -#include -#include -#include -#include -#include - +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include #include "../../fvwm/module.h" +#include "config.h" #ifdef HAVE_FCNTL_H #include @@ -48,42 +45,39 @@ extern int save_color_limit; -#define ICON_EVENTS (ExposureMask |\ -ButtonReleaseMask | ButtonPressMask | EnterWindowMask | LeaveWindowMask) +#define ICON_EVENTS \ + (ExposureMask | ButtonReleaseMask | ButtonPressMask | \ + EnterWindowMask | LeaveWindowMask) /**************************************************************************** * * Creates an Icon Window * ****************************************************************************/ -void CreateIconWindow(struct icon_info *item) +void +CreateIconWindow(struct icon_info *item) { - unsigned long valuemask; /* mask for create windows */ - XSetWindowAttributes attributes; /* attributes for create windows */ - - attributes.background_pixel = icon_back_pix; - attributes.event_mask = ExposureMask; - valuemask = CWEventMask | CWBackPixel; - - /* pixmap */ - if (max_icon_height != 0){ - item->icon_pixmap_w = - XCreateWindow(dpy, icon_win, 0, 0, - max(max_icon_width,item->icon_w), - max(max_icon_height,item->icon_h), - 0,CopyFromParent,CopyFromParent, - CopyFromParent,valuemask,&attributes); - XSelectInput(dpy, item->icon_pixmap_w, ICON_EVENTS); - } - - /* label */ - item->IconWin = - XCreateWindow(dpy, icon_win, 0, 0, - max_icon_width, - max_icon_height + 10, - 0,CopyFromParent,CopyFromParent, - CopyFromParent,valuemask,&attributes); - XSelectInput(dpy, item->IconWin, ICON_EVENTS); + unsigned long valuemask; /* mask for create windows */ + XSetWindowAttributes attributes; /* attributes for create windows */ + + attributes.background_pixel = icon_back_pix; + attributes.event_mask = ExposureMask; + valuemask = CWEventMask | CWBackPixel; + + /* pixmap */ + if (max_icon_height != 0) { + item->icon_pixmap_w = XCreateWindow(dpy, icon_win, 0, 0, + max(max_icon_width, item->icon_w), + max(max_icon_height, item->icon_h), 0, CopyFromParent, + CopyFromParent, CopyFromParent, valuemask, &attributes); + XSelectInput(dpy, item->icon_pixmap_w, ICON_EVENTS); + } + + /* label */ + item->IconWin = XCreateWindow(dpy, icon_win, 0, 0, max_icon_width, + max_icon_height + 10, 0, CopyFromParent, CopyFromParent, + CopyFromParent, valuemask, &attributes); + XSelectInput(dpy, item->IconWin, ICON_EVENTS); } /**************************************************************************** @@ -91,108 +85,108 @@ void CreateIconWindow(struct icon_info *item) * Loads an icon file and combines icon shape masks after a resize * ****************************************************************************/ -void ConfigureIconWindow(struct icon_info *item) +void +ConfigureIconWindow(struct icon_info *item) { - Pixmap temp; - int hr = icon_relief/2; - - XSelectInput(dpy, item->id, PropertyChangeMask); - item->wmhints = XGetWMHints(dpy, item->id); - - if (max_icon_height == 0) - return; - - if (item->icon_file != NULL && (!(item->extra_flags & DEFAULTICON) || !(item->wmhints && - item->wmhints->flags & - (IconPixmapHint|IconWindowHint)))){ - /* monochrome bitmap */ - GetBitmapFile(item); - - /* color pixmap */ - if((item->icon_w == 0)&&(item->icon_h == 0)) - GetXPMFile(item); - } - - /* special thanks to Rich Neitzel - for his patch to handle icon windows */ - if((item->icon_h == 0)&&(item->icon_w == 0)&& - (item->wmhints) && (item->wmhints->flags & IconWindowHint)) - GetIconWindow(item); - - /* icon bitmap from the application */ - if((item->icon_h == 0)&&(item->icon_w == 0)&& - (item->wmhints)&&(item->wmhints->flags & IconPixmapHint)) - GetIconBitmap(item); + Pixmap temp; + int hr = icon_relief / 2; + + XSelectInput(dpy, item->id, PropertyChangeMask); + item->wmhints = XGetWMHints(dpy, item->id); + + if (max_icon_height == 0) + return; + + if (item->icon_file != NULL && + (!(item->extra_flags & DEFAULTICON) || + !(item->wmhints && item->wmhints->flags & + (IconPixmapHint | IconWindowHint)))) { + /* monochrome bitmap */ + GetBitmapFile(item); + + /* color pixmap */ + if ((item->icon_w == 0) && (item->icon_h == 0)) + GetXPMFile(item); + } + + /* special thanks to Rich Neitzel + for his patch to handle icon windows */ + if ((item->icon_h == 0) && (item->icon_w == 0) && (item->wmhints) && + (item->wmhints->flags & IconWindowHint)) + GetIconWindow(item); + + /* icon bitmap from the application */ + if ((item->icon_h == 0) && (item->icon_w == 0) && (item->wmhints) && + (item->wmhints->flags & IconPixmapHint)) + GetIconBitmap(item); #ifdef XPM #ifdef SHAPE - if (item->icon_maskPixmap != None) - { - XShapeCombineMask(dpy, item->icon_pixmap_w, ShapeBounding, - hr, hr, item->icon_maskPixmap, ShapeSet); - } + if (item->icon_maskPixmap != None) { + XShapeCombineMask(dpy, item->icon_pixmap_w, ShapeBounding, hr, + hr, item->icon_maskPixmap, ShapeSet); + } #endif #endif - if(item->icon_depth == -1) - { - temp = item->iconPixmap; - item->iconPixmap = - XCreatePixmap(dpy, Root, item->icon_w, - item->icon_h,d_depth); - XCopyPlane(dpy,temp,item->iconPixmap,NormalGC, - 0,0,item->icon_w,item->icon_h,0,0,1); - } + if (item->icon_depth == -1) { + temp = item->iconPixmap; + item->iconPixmap = XCreatePixmap( + dpy, Root, item->icon_w, item->icon_h, d_depth); + XCopyPlane(dpy, temp, item->iconPixmap, NormalGC, 0, 0, + item->icon_w, item->icon_h, 0, 0, 1); + } } -void AdjustIconWindow(struct icon_info *item, int n) +void +AdjustIconWindow(struct icon_info *item, int n) { - int x=0,y=0,w,h,h2,h3,w3; - - w3 = w = max_icon_width + icon_relief; - h3 = h2 = max_icon_height + icon_relief; - h = h2 + 6 + font->ascent + font->descent; - - switch (primary){ - case LEFT: - case RIGHT: - if (secondary == BOTTOM) - y = icon_win_height - (n / Lines + 1)*(h + interval); - else if (secondary == TOP) - y = (n / Lines)*(h + interval) + interval; - - if (primary == LEFT) - x = (n % Lines)*(w + interval) + interval; - else - x = icon_win_width - (n % Lines + 1)*(w + interval); - break; - case TOP: - case BOTTOM: - if (secondary == RIGHT) - x = icon_win_width - (n / Lines + 1)*(w + interval); - else if (secondary == LEFT) - x = (n / Lines)*(w + interval) + interval; - - if (primary == TOP) - y = (n % Lines)*(h + interval) + interval; - else - y = icon_win_height - (n % Lines + 1)*(h + interval); - break; - default: - break; - } - - item->x = x; - item->y = y; - - if (item->icon_w > 0 && item->icon_h > 0){ - w3 = min(max_icon_width, item->icon_w) + icon_relief; - h3 = min(max_icon_height, item->icon_h) + icon_relief; - } - if (max_icon_height != 0) - XMoveResizeWindow(dpy, item->icon_pixmap_w, x + (w - w3)/2, - y + (h2 - h3)/2,w3,h3); - XMoveResizeWindow(dpy, item->IconWin, x,y + h2,w,h - h2); + int x = 0, y = 0, w, h, h2, h3, w3; + + w3 = w = max_icon_width + icon_relief; + h3 = h2 = max_icon_height + icon_relief; + h = h2 + 6 + font->ascent + font->descent; + + switch (primary) { + case LEFT: + case RIGHT: + if (secondary == BOTTOM) + y = icon_win_height - (n / Lines + 1) * (h + interval); + else if (secondary == TOP) + y = (n / Lines) * (h + interval) + interval; + + if (primary == LEFT) + x = (n % Lines) * (w + interval) + interval; + else + x = icon_win_width - (n % Lines + 1) * (w + interval); + break; + case TOP: + case BOTTOM: + if (secondary == RIGHT) + x = icon_win_width - (n / Lines + 1) * (w + interval); + else if (secondary == LEFT) + x = (n / Lines) * (w + interval) + interval; + + if (primary == TOP) + y = (n % Lines) * (h + interval) + interval; + else + y = icon_win_height - (n % Lines + 1) * (h + interval); + break; + default: + break; + } + + item->x = x; + item->y = y; + + if (item->icon_w > 0 && item->icon_h > 0) { + w3 = min(max_icon_width, item->icon_w) + icon_relief; + h3 = min(max_icon_height, item->icon_h) + icon_relief; + } + if (max_icon_height != 0) + XMoveResizeWindow(dpy, item->icon_pixmap_w, x + (w - w3) / 2, + y + (h2 - h3) / 2, w3, h3); + XMoveResizeWindow(dpy, item->IconWin, x, y + h2, w, h - h2); } /*************************************************************************** @@ -200,215 +194,215 @@ void AdjustIconWindow(struct icon_info *item, int n) * Looks for a monochrome icon bitmap file * **************************************************************************/ -void GetBitmapFile(struct icon_info *item) +void +GetBitmapFile(struct icon_info *item) { - char *path = NULL; - int HotX,HotY; - - path = findIconFile(item->icon_file, iconPath,R_OK); - if(path == NULL)return; - - if(XReadBitmapFile (dpy, Root,path,(unsigned int *)&item->icon_w, - (unsigned int *)&item->icon_h, - &item->iconPixmap, - (int *)&HotX, - (int *)&HotY) != BitmapSuccess) - { - item->icon_w = 0; - item->icon_h = 0; - } - else - item->icon_depth = 1; - - item->icon_w = min(max_icon_width, item->icon_w); - item->icon_h = min(max_icon_height, item->icon_h); - item->icon_maskPixmap = None; - free(path); + char *path = NULL; + int HotX, HotY; + + path = findIconFile(item->icon_file, iconPath, R_OK); + if (path == NULL) + return; + + if (XReadBitmapFile(dpy, Root, path, (unsigned int *)&item->icon_w, + (unsigned int *)&item->icon_h, &item->iconPixmap, (int *)&HotX, + (int *)&HotY) != BitmapSuccess) { + item->icon_w = 0; + item->icon_h = 0; + } else + item->icon_depth = 1; + + item->icon_w = min(max_icon_width, item->icon_w); + item->icon_h = min(max_icon_height, item->icon_h); + item->icon_maskPixmap = None; + free(path); } - /**************************************************************************** * * Looks for a color XPM icon file * ****************************************************************************/ -void GetXPMFile(struct icon_info *item) +void +GetXPMFile(struct icon_info *item) { #ifdef XPM - XWindowAttributes root_attr; - XpmAttributes xpm_attributes; - char *path = NULL; - int rc; - XpmImage my_image; - - path = findIconFile(item->icon_file, pixmapPath,R_OK); - if(path == NULL)return; - - XGetWindowAttributes(dpy,Root,&root_attr); - xpm_attributes.colormap = root_attr.colormap; - xpm_attributes.closeness = 40000; /* same closeness used elsewhere */ - xpm_attributes.valuemask = XpmSize|XpmReturnPixels|XpmColormap|XpmCloseness; - rc = XpmReadFileToXpmImage(path, &my_image, NULL); - if (rc != XpmSuccess) { - fprintf(stderr, "Problem reading pixmap %s, rc %d\n", path, rc); - free(path); - return; - } - color_reduce_pixmap(&my_image,save_color_limit); - rc = XpmCreatePixmapFromXpmImage(dpy,Root, &my_image, - &item->iconPixmap, - &item->icon_maskPixmap, - &xpm_attributes); - if (rc != XpmSuccess) { - fprintf(stderr, "Problem creating pixmap from image, rc %d\n", rc); - free(path); - return; - } - item->icon_w = min(max_icon_width, my_image.width); - item->icon_h = min(max_icon_height, my_image.height); - item->icon_depth = d_depth; - free(path); + XWindowAttributes root_attr; + XpmAttributes xpm_attributes; + char *path = NULL; + int rc; + XpmImage my_image; + + path = findIconFile(item->icon_file, pixmapPath, R_OK); + if (path == NULL) + return; + + XGetWindowAttributes(dpy, Root, &root_attr); + xpm_attributes.colormap = root_attr.colormap; + xpm_attributes.closeness = 40000; /* same closeness used elsewhere */ + xpm_attributes.valuemask = + XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness; + rc = XpmReadFileToXpmImage(path, &my_image, NULL); + if (rc != XpmSuccess) { + fprintf(stderr, "Problem reading pixmap %s, rc %d\n", path, rc); + free(path); + return; + } + color_reduce_pixmap(&my_image, save_color_limit); + rc = XpmCreatePixmapFromXpmImage(dpy, Root, &my_image, + &item->iconPixmap, &item->icon_maskPixmap, &xpm_attributes); + if (rc != XpmSuccess) { + fprintf( + stderr, "Problem creating pixmap from image, rc %d\n", rc); + free(path); + return; + } + item->icon_w = min(max_icon_width, my_image.width); + item->icon_h = min(max_icon_height, my_image.height); + item->icon_depth = d_depth; + free(path); #endif /* XPM */ } /*************************************************************************** -* + * * * Looks for an application supplied icon window * *************************************************************************** -*/ -void GetIconWindow(struct icon_info *item) + */ +void +GetIconWindow(struct icon_info *item) { - int x, y; - unsigned int bw; - Window Junkroot; + int x, y; + unsigned int bw; + Window Junkroot; - if(!XGetGeometry(dpy, item->wmhints->icon_window, &Junkroot, - &x, &y, (unsigned int *)&item->icon_w, - (unsigned int *)&item->icon_h, - &bw, (unsigned int *)&item->icon_depth)) - return; + if (!XGetGeometry(dpy, item->wmhints->icon_window, &Junkroot, &x, &y, + (unsigned int *)&item->icon_w, (unsigned int *)&item->icon_h, + &bw, (unsigned int *)&item->icon_depth)) + return; - XDestroyWindow(dpy, item->icon_pixmap_w); - item->icon_pixmap_w = item->wmhints->icon_window; + XDestroyWindow(dpy, item->icon_pixmap_w); + item->icon_pixmap_w = item->wmhints->icon_window; #ifdef SHAPE - if (item->wmhints->flags & IconMaskHint) - { - item->flags |= SHAPED_ICON; - item->icon_maskPixmap = item->wmhints->icon_mask; - } + if (item->wmhints->flags & IconMaskHint) { + item->flags |= SHAPED_ICON; + item->icon_maskPixmap = item->wmhints->icon_mask; + } #endif - item->icon_w = min(max_icon_width + icon_relief, item->icon_w); - item->icon_h = min(max_icon_height + icon_relief, item->icon_h); + item->icon_w = min(max_icon_width + icon_relief, item->icon_w); + item->icon_h = min(max_icon_height + icon_relief, item->icon_h); - XReparentWindow(dpy, item->icon_pixmap_w, icon_win, 0, 0); - XSetWindowBorderWidth(dpy, item->icon_pixmap_w, 0); - item->flags &= ~ICON_OURS; + XReparentWindow(dpy, item->icon_pixmap_w, icon_win, 0, 0); + XSetWindowBorderWidth(dpy, item->icon_pixmap_w, 0); + item->flags &= ~ICON_OURS; } /*************************************************************************** -* + * * * Looks for an application supplied bitmap or pixmap * *************************************************************************** -*/ -void GetIconBitmap(struct icon_info *item) + */ +void +GetIconBitmap(struct icon_info *item) { - int x, y; - unsigned int bw, depth; - Window Junkroot; - GC gc; - - if (!XGetGeometry(dpy, item->wmhints->icon_pixmap, &Junkroot, &x, &y, - (unsigned int *)&item->icon_w, - (unsigned int *)&item->icon_h, &bw, &depth)) - return; - - item->icon_depth = depth; - item->icon_file = NULL; - item->icon_maskPixmap = None; + int x, y; + unsigned int bw, depth; + Window Junkroot; + GC gc; + + if (!XGetGeometry(dpy, item->wmhints->icon_pixmap, &Junkroot, &x, &y, + (unsigned int *)&item->icon_w, (unsigned int *)&item->icon_h, + &bw, &depth)) + return; + + item->icon_depth = depth; + item->icon_file = NULL; + item->icon_maskPixmap = None; #ifdef SHAPE - if (item->wmhints->flags & IconMaskHint) - { - item->flags |= SHAPED_ICON; - item->icon_maskPixmap = item->wmhints->icon_mask; - } + if (item->wmhints->flags & IconMaskHint) { + item->flags |= SHAPED_ICON; + item->icon_maskPixmap = item->wmhints->icon_mask; + } #endif - item->icon_w = min(max_icon_width, item->icon_w); - item->icon_h = min(max_icon_height, item->icon_h); + item->icon_w = min(max_icon_width, item->icon_w); + item->icon_h = min(max_icon_height, item->icon_h); - item->iconPixmap = XCreatePixmap(dpy, Root, item->icon_w, - item->icon_h, depth); - gc = XCreateGC(dpy, item->iconPixmap, 0, NULL); - XCopyArea(dpy, item->wmhints->icon_pixmap, item->iconPixmap, - gc, 0, 0, item->icon_w, item->icon_h, 0, 0); - XFreeGC(dpy, gc); + item->iconPixmap = + XCreatePixmap(dpy, Root, item->icon_w, item->icon_h, depth); + gc = XCreateGC(dpy, item->iconPixmap, 0, NULL); + XCopyArea(dpy, item->wmhints->icon_pixmap, item->iconPixmap, gc, 0, 0, + item->icon_w, item->icon_h, 0, 0); + XFreeGC(dpy, gc); } -Bool GetBackPixmap(void) +Bool +GetBackPixmap(void) { - XWindowAttributes root_attr; + XWindowAttributes root_attr; #ifdef XPM - XpmAttributes xpm_attributes; - XpmImage my_image; + XpmAttributes xpm_attributes; + XpmImage my_image; #endif - char *path = NULL; - Pixmap tmp_bitmap, maskPixmap; - int x, y, w=0, h=0, rc; - - if (IconwinPixmapFile == NULL) - return False; - - if ((path = findIconFile(IconwinPixmapFile, iconPath,R_OK)) != NULL){ - if (XReadBitmapFile(dpy, Root,path,(unsigned int *)&w, - (unsigned int *)&h, &tmp_bitmap, - (int *)&x, (int *)&y)!= BitmapSuccess) - w = h = 0; - else{ - IconwinPixmap = XCreatePixmap(dpy, Root, w, h, d_depth); - XCopyPlane(dpy, tmp_bitmap, IconwinPixmap, NormalGC, 0, 0, w, h, - 0, 0, 1); - XFreePixmap(dpy, tmp_bitmap); - } - free(path); - } - + char *path = NULL; + Pixmap tmp_bitmap, maskPixmap; + int x, y, w = 0, h = 0, rc; + + if (IconwinPixmapFile == NULL) + return False; + + if ((path = findIconFile(IconwinPixmapFile, iconPath, R_OK)) != NULL) { + if (XReadBitmapFile(dpy, Root, path, (unsigned int *)&w, + (unsigned int *)&h, &tmp_bitmap, (int *)&x, + (int *)&y) != BitmapSuccess) + w = h = 0; + else { + IconwinPixmap = XCreatePixmap(dpy, Root, w, h, d_depth); + XCopyPlane(dpy, tmp_bitmap, IconwinPixmap, NormalGC, 0, + 0, w, h, 0, 0, 1); + XFreePixmap(dpy, tmp_bitmap); + } + free(path); + } + #ifdef XPM - if ( w == 0 && h == 0 && (path = findIconFile(IconwinPixmapFile, - pixmapPath,R_OK)) != NULL) - { - XGetWindowAttributes(dpy,Root,&root_attr); - xpm_attributes.colormap = root_attr.colormap; - xpm_attributes.closeness = 40000; /* same closeness used elsewhere */ - xpm_attributes.valuemask = XpmSize|XpmReturnPixels|XpmColormap| - XpmCloseness; - rc = XpmReadFileToXpmImage(path, &my_image, NULL); - if (rc != XpmSuccess) { - fprintf(stderr, "Problem reading pixmap %s, rc %d\n", path, rc); - free(path); - return False; - } - color_reduce_pixmap(&my_image,save_color_limit); - rc = XpmCreatePixmapFromXpmImage(dpy,Root, &my_image, - &IconwinPixmap, - &maskPixmap, - &xpm_attributes); - if (rc != XpmSuccess) { - fprintf(stderr, "Problem creating pixmap from image, rc %d\n", rc); - free(path); - return False; - } - w = my_image.width; - h = my_image.height; - free(path); - } + if (w == 0 && h == 0 && + (path = findIconFile(IconwinPixmapFile, pixmapPath, R_OK)) != + NULL) { + XGetWindowAttributes(dpy, Root, &root_attr); + xpm_attributes.colormap = root_attr.colormap; + xpm_attributes.closeness = + 40000; /* same closeness used elsewhere */ + xpm_attributes.valuemask = + XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness; + rc = XpmReadFileToXpmImage(path, &my_image, NULL); + if (rc != XpmSuccess) { + fprintf(stderr, "Problem reading pixmap %s, rc %d\n", + path, rc); + free(path); + return False; + } + color_reduce_pixmap(&my_image, save_color_limit); + rc = XpmCreatePixmapFromXpmImage(dpy, Root, &my_image, + &IconwinPixmap, &maskPixmap, &xpm_attributes); + if (rc != XpmSuccess) { + fprintf(stderr, + "Problem creating pixmap from image, rc %d\n", rc); + free(path); + return False; + } + w = my_image.width; + h = my_image.height; + free(path); + } #endif - if (w != 0 && h != 0) - return True; - return False; + if (w != 0 && h != 0) + return True; + return False; } Index: fvwm/modules/FvwmIconMan/FvwmIconMan.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/FvwmIconMan.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/FvwmIconMan.1 --- fvwm/modules/FvwmIconMan/FvwmIconMan.1 +++ fvwm/modules/FvwmIconMan/FvwmIconMan.1 @@ -1,6 +1,6 @@ .\" $OpenBSD: FvwmIconMan.1,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $ .\" t -.\" @(#)FvwmIconMan.1 6/17/1998 +.\" @(#)FvwmIconMan.1 6/17/1998 .de EX \"Begin example .ne 5 .if n .sp 1 @@ -14,15 +14,14 @@ .if n .sp 1 .if t .sp .5 .. -.TH FvwmIconMan 1 "June 17, 1998" 1.3 +.TH FVWMICONMAN 1 "June 17, 1998" "1.3" "FVWM Modules" .UC .SH NAME FvwmIconMan \- an Fvwm Icon Manager .SH SYNOPSIS FvwmIconMan is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -FvwmIconMan is an icon manager modeled after the TWM icon manager. The user +FvwmIconMan is an icon manager modeled after the TWM icon manager. The user may have multiple icon managers, each of which armed with a list of window types which it manages. For example, the user may have one manager which lists only emacs windows, and another which lists everything else. You may also @@ -35,16 +34,15 @@ maximum number of rows (and then grows horizontally), or stay at a fixed size, and adjust the size of the window buttons to fit (think win95's Taskbar). And when support is compiled in for the X Shape extension, then the manager windows may be shaped. - +.PP You can specify actions to be run when mouse, or key events are received. For example, you could bind the first mouse button to iconify the selected window, and make bindings for the arrow keys to navigate the manager window without the mouse. - +.PP FvwmIconMan can be set to display which window currently has the keyboard focus, and by binding the select event (see below) to the fvwm Focus function, you can emulate the TWM icon manager's behavior. - .SH INITIALIZATION During initialization, FvwmIconMan searches though the fvwm configuration file for the options which are described below. It is highly recommended that you @@ -52,34 +50,34 @@ make FvwmIconMan be a sticky window. And if you want to make use of the followfocus option, and/or binding an action to Focus, then you should make FvwmIconMan clicktofocus. Also, when using the Shape option, it's recommended that the FvwmIconMan window not be decorated at all by fvwm. - .SH INVOCATION -FvwmIconMan can be invoked by inserting the line 'Module FvwmIconMan' in the .fvwmrc file. If FvwmIconMan is to be spawned during fvwm's initialization, +FvwmIconMan can be invoked by inserting the line 'Module FvwmIconMan' in the +\&.fvwmrc file. +If FvwmIconMan is to be spawned during fvwm's initialization, then this line should be placed in the InitFunction and ResetFunction declarations, or it can be bound to a menu, mouse button, or keystroke to invoke it later. FvwmIconMan should be placed in the ModulePath (defined in the .fvwmrc file) in order for fvwm to find it. - +.PP If you wish to run FvwmIconMan in a transient mode, such as with the built in -window list, then pass Transient as an argument. The invocation "Module -FvwmIconMan Transient" will do nicely. In this mode, FvwmIconMan will pop up -one manager window directly under the cursor. When the mouse button is -released, it will execute the appropriate action, and then exit. Things are -somewhat complicated by the fact that you can specify that FvwmIconMan create -multiple manager windows, behavior which is unsuitable when running -transiently. So, when running transiently, FvwmIconMan will only create one -manager window. Use the manager id 'transient' to specify options for this -manager window. - +window list, then pass Transient as an argument. +The invocation "Module FvwmIconMan Transient" will do nicely. +In this mode, FvwmIconMan will pop up one manager window directly under the +cursor. +When the mouse button is released, it will execute the appropriate action, and +then exit. +Things are somewhat complicated by the fact that you can specify that +FvwmIconMan create multiple manager windows, behavior which is unsuitable when +running transiently. +So, when running transiently, FvwmIconMan will only create one manager window. +Use the manager id 'transient' to specify options for this manager window. .SH CONFIGURATION OPTIONS REFERENCE CHART FvwmIconMan has acquired quite a few options. I assume others share my dislike of paging though a long manpage, so here is a terse reference chart describing the available options. They are described in more detail in the next section. - -.ft C \" Courier +.PP .nf Name Description Default -.ft P action binds command to event Mouse 0 N sendcommand Iconify background default background gray @@ -106,13 +104,11 @@ titlebutton style for title button raisededge black grey usewinlist honor WinListSkip? true .fi - .SH CONFIGURATION OPTIONS With the exception of the nummanagers option, all of the options may be defined on a per-manager basis. So, for example, the user may have his emacs manager with a red foreground, and his xterm manager with a blue one. A configuration line may therefore have one of two forms: - .IP "*FvwmIconMan*optionname optionvalue" To specify that the \fIoptionname\fP takes the value \fIoptionvalue\fP for all managers. @@ -122,61 +118,49 @@ for manager \fImanagerid\fP. \fIMangerid\fP may either be a positive integer, or the string "transient". An integral id refers to managers which FvwmIconMan creates when running normally, and an id of "transient" refers to the single manager which FvwmIconMan creates when running transiently. - -.PP The following options may be specified: - .IP "*FvwmIconMan*nummanagers \fInum\fP" \fInum\fP is a positive integer specifying the total number of icon managers. Since FvwmIconMan would like to know how many managers there are before handling any manager specific options, this should come first. The default is 1. - .IP "*FvwmIconMan*[id*]action \fItype\fP \fIbinding\fP" Binds an FvwmIconMan command to an event. \fIType\fP may be one of the values: Key, Mouse, or Select. Actions are described in the following section ACTIONS. - .IP "*FvwmIconMan*[id*]background \fIbackground\fP" Specifies the default background color. - .IP "*FvwmIconMan*[id*]buttongeometry \fIgeometry\fP" Specifies the initial geometry of an individual button in pixels. If the specified height is 0, then the button height is determined from the font size. X and Y coordinates are ignored. - .IP "*FvwmIconMan*[id*]drawicons \fIvalue\fP" If your version of fvwm2 is capable of using MiniIcons, then this option determines if FvwmIconMan displays the MiniIcons. Otherwise, it generates an error message. "true" means that MiniIcons are shown for iconified windows, "false" that MiniIcons are never shown, and "always" that MiniIcons are shown for all windows. - -.IP "*FvwmIconMan*[id*]focusbutton \fIstyle\fP [\fIforecolor\fP \fIbackcolor\fP]" +.IP "*FvwmIconMan*[id*]focusbutton \fIstyle\fP" +Optional \fIforecolor\fP and \fIbackcolor\fP values may follow. Same as the plainbutton option, but specifies the look of buttons whose windows have the keyboard focus. - -.IP "*FvwmIconMan*[id*]focusandselectbutton \fIstyle\fP [\fIforecolor\fP \fIbackcolor\fP]" +.IP "*FvwmIconMan*[id*]focusandselectbutton \fIstyle\fP" +Optional \fIforecolor\fP and \fIbackcolor\fP values may follow. Same as the plainbutton option, but specifies the look of buttons which are both selected, and have the keyboard focus. - .IP "*FvwmIconMan*[id*]font \fIfont\fP" Specifies the font to be used for labeling the buttons. The default is 8x13. - .IP "*FvwmIconMan*[id*]foreground \fIforeground\fP" Specifies the default foreground color. - .IP "*FvwmIconMan*[id*]format \fIformatstring\fP" A printf like format string which describes the string to be printed in the manager window for each managed window. Possible flags are: %t, %i, %c, and %r for the window's title, icon, class, or resource name, respectively. The default is "%c: %i". \fBWarning\fP: m4 reserves the word \fIformat\fP, so if you use m4, take appropriate action. - .IP "*FvwmIconMan*[id*]iconname \fIiconstring\fP" Specifies the window icon name for that manager window. \fIIconstring\fP may either be a single word, or a string enclosed in quotes. The default is "FvwmIconMan". - .IP "*FvwmIconMan*[id*]managergeometry \fIgeometry\fP" Specifies the initial geometry of the manager, in units of buttons. If \fIheight\fP is 0, then the manager will use \fIwidth\fP columns, and will @@ -186,14 +170,13 @@ both are nonzero, then the manager window will be exactly that size, and stay that way. As columns are created, the buttons will narrow to accommodate. If the geometry is specified with a negative y coordinate, then the window manager will grow upwards. Otherwise, it will grow downwards. - -.IP "*FvwmIconMan*[id*]plainbutton \fIstyle\fP [\fIforecolor\fP \fIbackcolor\fP]" +.IP "*FvwmIconMan*[id*]plainbutton \fIstyle\fP" +Optional \fIforecolor\fP and \fIbackcolor\fP values may follow. Specifies how normal buttons look. \fIstyle\fP may be one of \fIflat\fP, \fIup\fP, \fIdown\fP, \fIraisededge\fP, or \fIsunkedge\fP, and describes how the button is drawn. The color options are both optional, and if not set, then the default colors are used. If on a monochrome screen, then the \fIstyle\fP option is ignored, but must still be set. - .IP "*FvwmIconMan*[id*]resolution \fIresolution\fP" Specifies when the manager will display an entry for a certain window. \fIresolution\fP may take one of the following values: global, desk, @@ -201,30 +184,27 @@ or page. If global, then all windows of the appropriate type (see the show and dontshow options below) will be shown. If desk, then only those windows on the current desk will be down. And if page, then only those windows on the current page will be shown. The default is global. - -.IP "*FvwmIconMan*[id*]selectbutton \fIstyle\fP [\fIforecolor\fP \fIbackcolor\fP]" +.IP "*FvwmIconMan*[id*]selectbutton \fIstyle\fP" +Optional \fIforecolor\fP and \fIbackcolor\fP values may follow. Same as the plainbutton option, but specifies the look of buttons when the mouse is over them. - .IP "*FvwmIconMan*[id*]shape \fIboolean\fP" -If \fITrue\fP, then use make the window shaped. Probably only useful if you +If \fITrue\fP, then make the window shaped. Probably only useful if you have multiple columns or rows. If FvwmIconMan wasn't compiled to support the Shape extension, this generates an error message. When using shaped windows, it's recommended that a fvwm style is made for FvwmIconMan that has no borders. Otherwise, fvwm will get confused. - .IP "*FvwmIconMan*[id*]title \fItitlestring\fP" Specifies the window title string for that manager window. \fITitlestring\fP may either be a single word, or a string enclosed in quotes. The default is "FvwmIconMan". This will be drawn in the titlebar of the manager window, if any, and in the title button, which is the button drawn when the manager is empty. - -.IP "*FvwmIconMan*[id*]titlebutton \fIstyle\fP [\fIforecolor\fP \fIbackcolor\fP]" +.IP "*FvwmIconMan*[id*]titlebutton \fIstyle\fP" +Optional \fIforecolor\fP and \fIbackcolor\fP values may follow. Same as the plainbutton option, but specifies the look of the title button (the button drawn when the manager is empty). The manager's title is drawn in the title button. - .PP The two following options control which windows get handled by which managers. A manager can get two lists, one of windows to show, and one of @@ -240,35 +220,29 @@ the same format used in the fvwm style command (minimalistic shell pattern matching). Quotes around the pattern will be taken as part of the expression. If a window could be handled by more than one manager, then the manager with the lowest id gets it. - .IP "*FvwmIconMan*[id*]show \fIpattern list\fP" If a window matches one of the patterns in the list, then it may be handled by this manager. - .IP "*FvwmIconMan*[id*]dontshow \fIpattern list\fP" If a window matches one of the patterns in the list, then it may not be handled by this manager. - .IP "*FvwmIconMan*[id*]usewinlist \fIboolean\fP" If \fItrue\fP, then honor the WinListSkip style flag. Otherwise, all windows are subject to possible management according to the show and dontshow lists. - .IP "*FvwmIconMan*[id*]followfocus \fIboolean\fP" If \fItrue\fP, then the button appearance reflects which window currently has focus. Default is false. - .IP "*FvwmIconMan*[id*]sort \fIvalue\fP" If \fIname\fP, then the manager list is sorted by name. If \fInamewithcase\fP, then it is sorted by name sensitive to case. If \fIid\fP, then the manager list is sorted by the window id, which never changes after the window is created. Or it can be set to \fInone\fP, which results in no sorting. Default is \fIname\fP. - .SH ACTIONS Actions are commands which may be bound to an event of the type: a keypress, a mouse click, or the mouse entering a window manager button - denoted by the action types \fIKey\fP, \fIMouse\fP, and \fISelect\fP. - +.PP Normally, actions bound to a mouse click are executed when the button is pressed. In transient mode, the action is executed when the button is released, since it is assumed that FvwmIconMan was bound to some mouse @@ -277,39 +251,35 @@ any modifier keys in this case, so if you bind FvwmIconMan to say, meta-button3, then it would be wise to ensure that the action you want to execute will be executed when the meta-button3 event occurs (which would be the button release, assuming you kept your finger on the meta key). - +.PP The syntax for actions are: - .IP "\fBKey actions\fP: Key \fIKeysym\fP \fIModifiers\fP \fIFunctionList\fP" \fIKeysym\fP and \fIModifiers\fP are exactly the same as for the fvwm \fIKey\fP command. - .IP "\fBMouse actions\fP: Mouse \fIButton\fP \fIModifiers\fP \fIFunctionList\fP" \fIButton\fP and \fIModifiers\fP are exactly the same as for the fvwm \fIMouse\fP command. - .IP "\fBSelect actions\fP: Select \fIFunctionList\fP" - .PP A \fIFunctionList\fP is a sequence of commands separated by commas. They are executed in left to right order, in one shared context - which currently only contains a pointer to the "current" button. If a button is selected (typically by the mouse pointer sitting on it) when the action is executed, then the current button is initialized to that button. Otherwise, it points to nothing. - +.PP Most of the available commands then modify this "current" button, either by moving it around, making it become the selected button, or sending commands to fvwm acting on the window represented by that button. Note that while this current button is initialized to be the selected button, the selected button does not implicitly follow it around. This way, the user can send commands to various windows, without changing which button is selected. - +.PP Commands take five types of arguments: \fIInteger\fP, \fIManager\fP, \fIWindow\fP, \fIButton\fP, and \fIString\fP. A \fIString\fP is a string specified exactly as for fvwm - either in quotes or as a single word not in quotes. Again, you may bind a sequence of commands to an event, by listing them separated by commas. - +.PP \fIWindow\fP and \fIButton\fP types look exactly the same in the .fvwmrc file, but are interpreted as either specifying a managed window, or a FvwmIconMan button representing a window. They can either be an integer (which @@ -325,11 +295,11 @@ manager after or before the current button, allowing navigation of the one dimensional list of windows which is drawn in the manager window. If the manager is sorted, \fINext\fP and \fIPrev\fP move through the windows in the sorted order. - +.PP The \fIManager\fP type can either be an integer, \fINext\fP, or \fIPrev\fP. The meaning is analogous to that of the \fIButton\fP type, but in terms of the integral index of the managers, restricted to managers which are nonempty. - +.PP The following functions are currently defined: .IP "bif \fIButton\fP \fIInteger/String\fP" A relative branch instruction. If \fIButton\fP is \fISelect\fP or \fIFocus\fP, @@ -339,53 +309,41 @@ then take the branch if there is a selected button or a focused button. If taken when the current button can move in that direction. If the branch is taken, then \fIInteger\fP commands are skipped. No backwards branches are allowed. - .IP "bifn \fIButton\fP \fIInteger/String\fP" The complement of bif. The branch is taken if \fIButton\fP evaluates to false, by the criteria listed for bif. - .IP "gotobutton \fIButton\fP" Sets current button to \fIButton\fP. If \fIButton\fP is an integer, then the current button is set to \fIButton\fP modulo the number of buttons, in the whichever manager contains the selected button, if any. - .IP "gotomanager \fIManager\fP" Sets button to button 0 of \fIManager\fP. This will only go to a visible, nonempty manager. So an integral argument is taken modulo the number of such managers. - .IP "jmp \fIInteger/String\fP" Executes a relative jump of \fIInteger\fP instructions. Backwards jumps are not allowed. The jump is computed relative to the instruction following the jmp. - .IP "label \fIString\fP" Provides a label that previous instructions can jump to. It will not be visible to subsequent jump instructions, and the same label can be used multiple times in the same instruction list (though it would be perverse to do so.) - .IP "print \fIString\fP" Prints \fIString\fP to the console. Useful for debugging actions. - .IP "quit" Quits FvwmIconMan. - .IP "ret" Stop executing the entire action. - .IP "select" Selects the current button, if any. If a select action has been specified, it will then be run. Therefore, it is considered unwise to set the select button in the select action. - .IP "sendcommand \fICommand\fP" Sends the fvwm command \fICommand\fP to the window represented by the current button, if any. - .IP "warp" Warps cursor to current button, if any. - .PP .B Examples: .EX @@ -394,63 +352,55 @@ gotobutton select, gotobutton Down, select Selects the button below the currently selected button. Since the current button is already initialized to the selected button, this may be shortened to "gotobutton Down , select". - .EX gotobutton Up, select .EE Selects the button above the currently selected button. - .EX gotobutton 0, select .EE Selects the first button of the current manager. If there is no current manager, which is the case when no button is selected, then this does nothing. - .EX gotobutton -1, select .EE Selects the last button of the current manager. - .EX gotobutton focus, select .EE Selects the button corresponding to the focused window. - .EX gotobutton focus, Iconify .EE Sends the fvwm command Iconify to the focused window. Note that this does not change the selected button. - .EX bif Next 3, gotobutton 0, select, ret, gotobutton Next, select .EE If a button is selected, and it's the last button, go to button 0. If it's not the last button, go to the next button. Otherwise, do nothing. Basically, this action cycles through all buttons in the current manager. - .EX -bif select 7, bif focus 3, gotomanager 0, select, ret, gotobutton focus, select, ret, gotobutton down, select +bif select 7, bif focus 3, gotomanager 0, select, ret, +gotobutton focus, select, ret, gotobutton down, select .EE This is good for sending to FvwmIconMan with a SendToModule command. If there is a selected button, it moves down. Otherwise, if there is a focused button, it is selected. Otherwise, button 0 of manager 0 gets selected. - .EX -bif select Select, bif focus Focus, gotomanager 0, select, ret, label Focus, gotobutton focus, select, ret, label Select, gotobutton down, select +bif select Select, bif focus Focus, gotomanager 0, select, ret, +label Focus, gotobutton focus, select, ret, label Select, +gotobutton down, select .EE Same as previous, but using the label instruction. - .PP In addition to being bound to keys and mice, actions can be sent from fvwm to FvwmIconMan via the SendToModule command. Don't quote the command when using SendToModule. Also, due to a bug in the current version of fvwm2, don't quote FvwmIconMan either. - .SH SAMPLE CONFIGURATIONS This first example is of a the simplest invocation of FvwmIconMan, which only has one manager, and handles all windows: - .nf .sp XCOMM############################################################## @@ -477,22 +427,26 @@ XCOMM Definitions used by the modules *FvwmIconMan*managergeometry 1x0-0+0 .sp .fi - This example is the Reader's Digest version of my personal configuration. It has two managers, one for emacs and one for everything else, minus things with no icon title. Only windows on the current page are displayed. The use of the \fIdrawicons\fP and \fIshape\fP options requires that fvwm and FvwmIconMan we compiled with the correct options. Note how the geometry and show options are specified per manager, and the others are common to all: - .nf .sp Style "FvwmIconMan" NoTitle, Sticky, WindowListSkip, BorderWidth 0 Style "FvwmIconMan" HandleWidth 0 -Key F8 A N SendToModule FvwmIconMan bif select Select, bif focus Focus, gotomanager 0, select, sendcommand WarpToWindow, ret, label Focus, gotobutton focus, select, sendcommand WarpToWindow, ret, label Select, gotobutton prev, select, sendcommand WarpToWindow -Key F9 A N SendToModule FvwmIconMan bif select Select, bif focus Focus, gotomanager 0, select, sendcommand WarpToWindow, ret, label Focus, gotobutton focus, select, sendcommand WarpToWindow, ret, label Select, gotobutton next, select, sendcommand WarpToWindow +Key F8 A N SendToModule FvwmIconMan bif select Select, bif focus Focus,\c + gotomanager 0, select, sendcommand WarpToWindow, ret, label Focus,\c + gotobutton focus, select, sendcommand WarpToWindow, ret, label Select,\c + gotobutton prev, select, sendcommand WarpToWindow +Key F9 A N SendToModule FvwmIconMan bif select Select, bif focus Focus,\c + gotomanager 0, select, sendcommand WarpToWindow, ret, label Focus,\c + gotobutton focus, select, sendcommand WarpToWindow, ret, label Select,\c + gotobutton next, select, sendcommand WarpToWindow *FvwmIconMan*numManagers 2 *FvwmIconMan*Resolution page @@ -501,9 +455,9 @@ Key F9 A N SendToModule FvwmIconMan bif select Select, bif focus Focus, gotomana *FvwmIconMan*font 7x13 *FvwmIconMan*usewinlist true *FvwmIconMan*drawicons true -*FvwmIconMan*shape true +*FvwmIconMan*shape true *FvwmIconMan*followfocus true -*FvwmIconMan*sort name +*FvwmIconMan*sort name *FvwmIconMan*plainbutton up white steelblue *FvwmIconMan*selectbutton down white steelblue *FvwmIconMan*focusbutton up white brown @@ -528,38 +482,28 @@ Key F9 A N SendToModule FvwmIconMan bif select Select, bif focus Focus, gotomana *FvwmIconMan*transient*dontshow icon=Untitled *FvwmIconMan*transient*action Mouse 0 A sendcommand select select Iconify -*FvwmIconMan*action Mouse 1 N sendcommand Iconify -*FvwmIconMan*action Mouse 2 N sendcommand WarpToWindow -*FvwmIconMan*action Mouse 3 N sendcommand "Module FvwmIdent FvwmIdent" -*FvwmIconMan*action Key Left N gotobutton Left, select -*FvwmIconMan*action Key Right N gotobutton Right, select -*FvwmIconMan*action Key Up N gotobutton Up, select -*FvwmIconMan*action Key Down N gotobutton Down, select -*FvwmIconMan*action Key q N quit +*FvwmIconMan*action Mouse 1 N sendcommand Iconify +*FvwmIconMan*action Mouse 2 N sendcommand WarpToWindow +*FvwmIconMan*action Mouse 3 N sendcommand "Module FvwmIdent FvwmIdent" +*FvwmIconMan*action Key Left N gotobutton Left, select +*FvwmIconMan*action Key Right N gotobutton Right, select +*FvwmIconMan*action Key Up N gotobutton Up, select +*FvwmIconMan*action Key Down N gotobutton Down, select +*FvwmIconMan*action Key q N quit .sp .fi - -.SH UNFINISHED BUSINESS -There is one bug that I know of. A honest to goodness solution to this would -be appreciated. When an icon manager is set to grow upwards or leftwards, on -some machines it may wander occasionally. - -It doesn't handle windows without resource names as gracefully as it should. - .SH AUTHOR Brady Montz (bradym@cs.arizona.edu). - .SH THANKS .nf Thanks to: - David Berson , - Gren Klanderman , - David Goldberg , - Pete Forman , - Neil Moore , - Josh M. Osborne , - Chris Siebenmann , - Bjorn Victor . - + David Berson , + Gren Klanderman , + David Goldberg , + Pete Forman , + Neil Moore , + Josh M. Osborne , + Chris Siebenmann , + Bjorn Victor . for contributing either code or truly keen ideas. Index: fvwm/modules/FvwmIconMan/FvwmIconMan.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/FvwmIconMan.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/FvwmIconMan.c --- fvwm/modules/FvwmIconMan/FvwmIconMan.c +++ fvwm/modules/FvwmIconMan/FvwmIconMan.c @@ -3,261 +3,229 @@ * for any purpose. */ -#include -#include -#include -#include #include "FvwmIconMan.h" + +#include +#include +#include +#include +#include + +#include "../../fvwm/module.h" #include "readconfig.h" #include "x.h" #include "xmanager.h" -#include "../../fvwm/module.h" - - static int fd_width; static volatile sig_atomic_t isTerminated = False; static char *IM_VERSION = "1.3"; static char const rcsid[] = - "$Id: FvwmIconMan.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; - + "$Id: FvwmIconMan.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; -static RETSIGTYPE TerminateHandler(int); +static void TerminateHandler(int); -char *copy_string (char **target, char *src) +char * +copy_string(char **target, char *src) { - int len = strlen (src); - ConsoleDebug (CORE, "copy_string: 1: 0x%lx\n", (unsigned long)*target); + int len = strlen(src); + ConsoleDebug(CORE, "copy_string: 1: 0x%lx\n", (unsigned long)*target); - if (*target) - Free (*target); + if (*target) + Free(*target); - ConsoleDebug (CORE, "copy_string: 2\n"); - *target = (char *)safemalloc ((len + 1) * sizeof (char)); - strcpy (*target, src); - ConsoleDebug (CORE, "copy_string: 3\n"); - return *target; + ConsoleDebug(CORE, "copy_string: 2\n"); + *target = (char *)xmalloc((len + 1) * sizeof(char)); + strlcpy(*target, src, len + 1); + ConsoleDebug(CORE, "copy_string: 3\n"); + return *target; } -#ifdef TRACE_MEMUSE - -long MemUsed = 0; - -void Free (void *p) +void +Free(void *p) { - struct malloc_header *head = (struct malloc_header *)p; - - if (p != NULL) { - head--; - if (head->magic != MALLOC_MAGIC) { - fprintf (stderr, "Corrupted memory found in Free\n"); - abort(); - return; - } - if (head->len > MemUsed) { - fprintf (stderr, "Free block too big\n"); - return; - } - MemUsed -= head->len; - free (head); - } + if (p != NULL) + free(p); } -void PrintMemuse (void) -{ - ConsoleDebug (CORE, "Memory used: %d\n", MemUsed); -} - -#else - -void Free (void *p) -{ - if (p != NULL) - free (p); -} - -void PrintMemuse (void) -{ -} - -#endif - - -static RETSIGTYPE +static void TerminateHandler(int sig) { - isTerminated = True; + isTerminated = True; } - -void ShutMeDown (int flag) +void +ShutMeDown(int flag) { - ConsoleDebug (CORE, "Bye Bye\n"); - exit (flag); + ConsoleDebug(CORE, "Bye Bye\n"); + exit(flag); } -void DeadPipe (int nothing) +void +DeadPipe(int nothing) { - ShutMeDown(0); + ShutMeDown(0); } -void SendFvwmPipe (char *message,unsigned long window) +void +SendFvwmPipe(char *message, unsigned long window) { - char *hold,*temp,*temp_msg; - hold=message; - - while(1) { - temp=strchr(hold,','); - if (temp!=NULL) { - temp_msg= (char *)safemalloc(temp-hold+1); - strncpy(temp_msg,hold,(temp-hold)); - temp_msg[(temp-hold)]='\0'; - hold=temp+1; - } else temp_msg=hold; - - SendText(Fvwm_fd, temp_msg, window); - - if(temp_msg!=hold) Free(temp_msg); - else break; - } + char *hold, *temp, *temp_msg; + hold = message; + + sandbox_x11_config("FvwmIconMan"); + + while (1) { + temp = strchr(hold, ','); + if (temp != NULL) { + temp_msg = (char *)xmalloc(temp - hold + 1); + strncpy(temp_msg, hold, (temp - hold)); + temp_msg[(temp - hold)] = '\0'; + hold = temp + 1; + } else + temp_msg = hold; + + SendText(Fvwm_fd, temp_msg, window); + + if (temp_msg != hold) + Free(temp_msg); + else + break; + } } -static void main_loop (void) +static void +main_loop(void) { - fd_set readset, saveset; - - FD_ZERO (&saveset); - FD_SET (Fvwm_fd[1], &saveset); - FD_SET (x_fd, &saveset); - - while( !isTerminated ) { - /* Check the pipes for anything to read, and block if - * there is nothing there yet ... - */ - readset = saveset; - if (select(fd_width,&readset,NULL,NULL,NULL) < 0) { - ConsoleMessage ("Internal error with select: errno=%d\n",errno); - } - else { - - if (FD_ISSET (x_fd, &readset) || XPending (theDisplay)) { - xevent_loop(); - } - if (FD_ISSET(Fvwm_fd[1],&readset)) { - ReadFvwmPipe(); - } - - } - } /* while */ + fd_set readset, saveset; + + FD_ZERO(&saveset); + FD_SET(Fvwm_fd[1], &saveset); + FD_SET(x_fd, &saveset); + + sandbox_x11_config("FvwmIconMan"); + while (!isTerminated) { + /* Check the pipes for anything to read, and block if + * there is nothing there yet ... + */ + readset = saveset; + if (select(fd_width, &readset, NULL, NULL, NULL) < 0) { + ConsoleMessage( + "Internal error with select: errno=%d\n", errno); + } else { + if (FD_ISSET(x_fd, &readset) || XPending(theDisplay)) { + xevent_loop(); + } + if (FD_ISSET(Fvwm_fd[1], &readset)) { + ReadFvwmPipe(); + } + } + } /* while */ } -int main (int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - int i; + char *temp, *s; + int i; #ifdef ELECTRIC_FENCE - extern int EF_PROTECT_BELOW, EF_PROTECT_FREE; + extern int EF_PROTECT_BELOW, EF_PROTECT_FREE; - EF_PROTECT_BELOW = 1; - EF_PROTECT_FREE = 1; + EF_PROTECT_BELOW = 1; + EF_PROTECT_FREE = 1; #endif #ifdef DEBUG_ATTACH - { - char buf[256]; - sprintf (buf, "%d", getpid()); - if (fork() == 0) { - chdir ("/home/bradym/src/FvwmIconMan"); - execl ("/usr/local/bin/ddd", "/usr/local/bin/ddd", "FvwmIconMan", - buf, NULL); - } - else { - int i, done = 0; - for (i = 0; i < (1 << 27) && !done; i++) ; - } - } + { + char buf[256]; + sprintf(buf, "%d", getpid()); + if (fork() == 0) { + chdir("/home/bradym/src/FvwmIconMan"); + execl("/usr/local/bin/ddd", "/usr/local/bin/ddd", + "FvwmIconMan", buf, NULL); + } else { + int i, done = 0; + for (i = 0; i < (1 << 27) && !done; i++) + ; + } + } #endif - OpenConsole(OUTPUT_FILE); + OpenConsole(OUTPUT_FILE); -#if 0 - ConsoleMessage ("PID = %d\n", getpid()); - ConsoleMessage ("Waiting for GDB to attach\n"); - sleep (10); -#endif + init_globals(); + init_winlists(); - init_globals(); - init_winlists(); + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; - temp = argv[0]; - s = strrchr (argv[0], '/'); - if (s != NULL) - temp = s + 1; + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", Module, + IM_VERSION); + ShutMeDown(1); + } + if (argc == 7 && !strcasecmp(argv[6], "Transient")) + globals.transient = 1; - if((argc != 6) && (argc != 7)) { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module, - IM_VERSION); - ShutMeDown (1); - } - if (argc == 7 && !strcasecmp (argv[6], "Transient")) - globals.transient = 1; - - Fvwm_fd[0] = atoi(argv[1]); - Fvwm_fd[1] = atoi(argv[2]); - init_display(); - init_boxes(); + Fvwm_fd[0] = atoi(argv[1]); + Fvwm_fd[1] = atoi(argv[2]); + init_display(); + init_boxes(); #ifdef HAVE_SIGACTION - { - struct sigaction sigact; - - sigemptyset(&sigact.sa_mask); -# ifdef SA_INTERRUPT - sigact.sa_flags = SA_INTERRUPT; -# else - sigact.sa_flags = 0; -# endif - sigact.sa_handler = TerminateHandler; - - sigaction(SIGPIPE, &sigact, NULL); - sigaction(SIGINT, &sigact, NULL); - sigaction(SIGHUP, &sigact, NULL); - sigaction(SIGTERM, &sigact, NULL); - sigaction(SIGQUIT, &sigact, NULL); - } + { + struct sigaction sigact; + + sigemptyset(&sigact.sa_mask); +#ifdef SA_INTERRUPT + sigact.sa_flags = SA_INTERRUPT; +#else + sigact.sa_flags = 0; +#endif + sigact.sa_handler = TerminateHandler; + + sigaction(SIGPIPE, &sigact, NULL); + sigaction(SIGINT, &sigact, NULL); + sigaction(SIGHUP, &sigact, NULL); + sigaction(SIGTERM, &sigact, NULL); + sigaction(SIGQUIT, &sigact, NULL); + } #else - /* We don't have sigaction(), so fall back to less robust methods. */ - signal(SIGPIPE, TerminateHandler); - signal(SIGINT, TerminateHandler); - signal(SIGHUP, TerminateHandler); - signal(SIGTERM, TerminateHandler); - signal(SIGQUIT, TerminateHandler); + /* We don't have sigaction(), so fall back to less robust methods. */ + signal(SIGPIPE, TerminateHandler); + signal(SIGINT, TerminateHandler); + signal(SIGHUP, TerminateHandler); + signal(SIGTERM, TerminateHandler); + signal(SIGQUIT, TerminateHandler); #endif - read_in_resources (argv[3]); + read_in_resources(argv[3]); - for (i = 0; i < globals.num_managers; i++) { - X_init_manager (i); - } + for (i = 0; i < globals.num_managers; i++) { + X_init_manager(i); + } - assert (globals.managers); - fd_width = GetFdWidth(); + assert(globals.managers); + fd_width = GetFdWidth(); - SetMessageMask(Fvwm_fd,M_CONFIGURE_WINDOW | M_RES_CLASS | M_RES_NAME | - M_ADD_WINDOW | M_DESTROY_WINDOW | M_ICON_NAME | - M_DEICONIFY | M_ICONIFY | M_END_WINDOWLIST | - M_NEW_DESK | M_NEW_PAGE | M_FOCUS_CHANGE | M_WINDOW_NAME | + SetMessageMask(Fvwm_fd, M_CONFIGURE_WINDOW | M_RES_CLASS | M_RES_NAME | + M_ADD_WINDOW | M_DESTROY_WINDOW | + M_ICON_NAME | M_DEICONIFY | M_ICONIFY | + M_END_WINDOWLIST | M_NEW_DESK | M_NEW_PAGE | + M_FOCUS_CHANGE | M_WINDOW_NAME | #ifdef MINI_ICONS - M_MINI_ICON | + M_MINI_ICON | #endif - M_STRING); + M_STRING); - SendInfo (Fvwm_fd, "Send_WindowList", 0); + SendInfo(Fvwm_fd, "Send_WindowList", 0); - main_loop(); + main_loop(); - return 0; + return 0; } Index: fvwm/modules/FvwmIconMan/FvwmIconMan.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/FvwmIconMan.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/FvwmIconMan.h --- fvwm/modules/FvwmIconMan/FvwmIconMan.h +++ fvwm/modules/FvwmIconMan/FvwmIconMan.h @@ -1,12 +1,14 @@ -#include "config.h" - -#include -#include +#ifndef FVWMICONMAN_H +#define FVWMICONMAN_H #include -#include #include +#include +#include +#include + +#include "config.h" #ifndef FVWM_VERSION #define FVWM_VERSION 2 @@ -28,311 +30,290 @@ #define DEFAULT_ACTION "Iconify" #endif -#define RECTANGLES_INTERSECT(x1,y1,w1,h1,x2,y2,w2,h2) \ - (((x1) + (w1) > (x2) && (x1) < (x2) + (w2)) && \ - ((y1) + (h1) > (y2) && (y1) < (y2) + (h2))) +#define RECTANGLES_INTERSECT(x1, y1, w1, h1, x2, y2, w2, h2) \ + (((x1) + (w1) > (x2) && (x1) < (x2) + (w2)) && \ + ((y1) + (h1) > (y2) && (y1) < (y2) + (h2))) #define MAX_ARGS 3 -#ifdef TRACE_MEMUSE +#define SET_BIT(field, bit) ((field) |= (bit)) +#define CLEAR_BIT(field, bit) ((field) &= ~(bit)) -#define MALLOC_MAGIC 0xdeadbeaf - -#define SET_BIT(field,bit) ((field) |= (bit)) -#define CLEAR_BIT(field,bit) ((field) &= ~(bit)) - -#define SET_BIT_TO_VAL(field,bit,val) ((val) ? SET_BIT (field,bit) : CLEAR_BIT (field, bit)) - -extern long MemUsed; - -struct malloc_header { - unsigned long magic, len; -}; - -#endif +#define SET_BIT_TO_VAL(field, bit, val) \ + ((val) ? SET_BIT(field, bit) : CLEAR_BIT(field, bit)) #ifdef DMALLOC /* What the heck is this?? */ #include #endif -extern void PrintMemuse (void); +extern void PrintMemuse(void); typedef unsigned long Ulong; typedef unsigned char Uchar; typedef signed char Schar; -typedef enum { - SHOW_GLOBAL = 0, - SHOW_DESKTOP = 1, - SHOW_PAGE = 2 -} Resolution; +typedef enum { SHOW_GLOBAL = 0, SHOW_DESKTOP = 1, SHOW_PAGE = 2 } Resolution; typedef enum { - BUTTON_FLAT, - BUTTON_UP, - BUTTON_DOWN, - BUTTON_EDGEUP, - BUTTON_EDGEDOWN + BUTTON_FLAT, + BUTTON_UP, + BUTTON_DOWN, + BUTTON_EDGEUP, + BUTTON_EDGEDOWN } ButtonState; /* The clicks must be the first three elements in this type, X callbacks - depend on it! */ -typedef enum { - SELECT, - MOUSE, - KEYPRESS, - NUM_ACTIONS -} Action; + depend on it! */ +typedef enum { SELECT, MOUSE, KEYPRESS, NUM_ACTIONS } Action; typedef enum { - PLAIN_CONTEXT = 0, - FOCUS_CONTEXT = 1, - SELECT_CONTEXT = 2, - FOCUS_SELECT_CONTEXT = 3, /* had better be FOCUS_CONTEXT | SELECT_CONTEXT */ - TITLE_CONTEXT = 4, - NUM_CONTEXTS + PLAIN_CONTEXT = 0, + FOCUS_CONTEXT = 1, + SELECT_CONTEXT = 2, + FOCUS_SELECT_CONTEXT = + 3, /* had better be FOCUS_CONTEXT | SELECT_CONTEXT */ + TITLE_CONTEXT = 4, + NUM_CONTEXTS } Contexts; typedef enum { - NO_NAME = 0, - TITLE_NAME = 1, - ICON_NAME = 2, - RESOURCE_NAME = 4, - CLASS_NAME = 8, - ALL_NAME = 15 + NO_NAME = 0, + TITLE_NAME = 1, + ICON_NAME = 2, + RESOURCE_NAME = 4, + CLASS_NAME = 8, + ALL_NAME = 15 } NameType; typedef struct win_list { - int n; - struct win_data *head, *tail; + int n; + struct win_data *head, *tail; } WinList; typedef struct string_list { - NameType type; - char *string; - struct string_list *next; + NameType type; + char *string; + struct string_list *next; } StringEl; typedef struct { - Uchar mask; - StringEl *list; + Uchar mask; + StringEl *list; } StringList; typedef enum { - NoArg, - IntArg, - StringArg, - ButtonArg, - WindowArg, - ManagerArg, - JmpArg + NoArg, + IntArg, + StringArg, + ButtonArg, + WindowArg, + ManagerArg, + JmpArg } BuiltinArgType; typedef enum { - NoButton, - SelectButton, - FocusButton, - AbsoluteButton, - UpButton, - DownButton, - LeftButton, - RightButton, - NextButton, - PrevButton + NoButton, + SelectButton, + FocusButton, + AbsoluteButton, + UpButton, + DownButton, + LeftButton, + RightButton, + NextButton, + PrevButton } ButtonType; /* doubles for manager too */ typedef struct { - int offset; - ButtonType base; + int offset; + ButtonType base; } ButtonValue; typedef struct builtin_arg { - BuiltinArgType type; - union { - char *string_value; - ButtonValue button_value; - int int_value; - } value; + BuiltinArgType type; + union { + char *string_value; + ButtonValue button_value; + int int_value; + } value; } BuiltinArg; typedef struct Function { - int (*func)(int numargs, BuiltinArg *args); - int numargs; - BuiltinArg args[MAX_ARGS]; - struct Function *next; - struct Function *prev; + int (*func)(int numargs, BuiltinArg *args); + int numargs; + BuiltinArg args[MAX_ARGS]; + struct Function *next; + struct Function *prev; } Function; -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 Modifier; /* Modifiers for keyboard state */ - char *Action; /* What to do? */ - Function *Function; - struct Binding *NextBinding, *LastBinding; +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 Modifier; /* Modifiers for keyboard state */ + char *Action; /* What to do? */ + Function *Function; + struct Binding *NextBinding, *LastBinding; } Binding; typedef struct win_data { - struct button *button; - /* stuff shadowed in the Button structure */ + struct button *button; + /* stuff shadowed in the Button structure */ #ifdef MINI_ICONS - FvwmPicture pic; + FvwmPicture pic; #endif - char *display_string; /* what gets shown in the manager window */ - Uchar iconified, state; - - Ulong desknum; - long x, y, width, height; - Ulong app_id; - Ulong fvwm_flags; - char *resname; - char *classname; - char *titlename; - char *iconname; - struct win_data *win_prev, *win_next; - struct win_manager *manager; - int app_id_set : 1; - int geometry_set : 1; - Uchar complete; + char *display_string; /* what gets shown in the manager window */ + Uchar iconified, state; + + Ulong desknum; + long x, y, width, height; + Ulong app_id; + Ulong fvwm_flags; + char *resname; + char *classname; + char *titlename; + char *iconname; + struct win_data *win_prev, *win_next; + struct win_manager *manager; + unsigned int app_id_set:1; + unsigned int geometry_set:1; + Uchar complete; } WinData; typedef struct button { - int index; /* index into button array */ - int x, y, w, h; /* current coords of button */ - struct { - int dirty_flags; + int index; /* index into button array */ + int x, y, w, h; /* current coords of button */ + struct { + int dirty_flags; #ifdef MINI_ICONS - FvwmPicture pic; + FvwmPicture pic; #endif - WinData *win; - char *display_string; - int x, y, w, h; - Uchar iconified, state; - } drawn_state; + WinData *win; + char *display_string; + int x, y, w, h; + Uchar iconified, state; + } drawn_state; } Button; typedef struct button_array { - int dirty_flags; - int num_buttons, drawn_num_buttons; /* size of buttons array */ - int num_windows, drawn_num_windows; /* number of windows with buttons */ - Button **buttons; + int dirty_flags; + int num_buttons, drawn_num_buttons; /* size of buttons array */ + int num_windows, drawn_num_windows; /* number of windows with buttons */ + Button **buttons; } ButtonArray; typedef enum { - GROW_HORIZ = 1, - GROW_VERT = 2, - GROW_UP = 4, - GROW_DOWN = 8, - GROW_LEFT = 16, - GROW_RIGHT = 32, - GROW_FIXED = 64 + GROW_HORIZ = 1, + GROW_VERT = 2, + GROW_UP = 4, + GROW_DOWN = 8, + GROW_LEFT = 16, + GROW_RIGHT = 32, + GROW_FIXED = 64 } GrowDirection; typedef struct { - /* Things which we can change go in here. - This like border width go in WinManager */ - int x, y, width, height; - int gravity_x, gravity_y; /* anchor point for window's gravity */ - int rows, cols; - int boxheight, boxwidth; - GrowDirection dir; + /* Things which we can change go in here. + This like border width go in WinManager */ + int x, y, width, height; + int gravity_x, gravity_y; /* anchor point for window's gravity */ + int rows, cols; + int boxheight, boxwidth; + GrowDirection dir; } ManGeometry; typedef struct { - int num_rects; - XRectangle rects[2]; + int num_rects; + XRectangle rects[2]; } ShapeState; typedef enum { - SortNone, /* no sorting */ - SortId, /* sort by window id */ - SortName, /* case insensitive name sorting */ - SortNameCase /* case sensitive name sorting */ + SortNone, /* no sorting */ + SortId, /* sort by window id */ + SortName, /* case insensitive name sorting */ + SortNameCase /* case sensitive name sorting */ } SortType; typedef struct win_manager { - unsigned int magic; - int index; - - /* .fvwm2rc options or things set as a result of options */ - Resolution res; - Pixel backcolor[NUM_CONTEXTS], forecolor[NUM_CONTEXTS]; - Pixel hicolor[NUM_CONTEXTS], shadowcolor[NUM_CONTEXTS]; - GC hiContext[NUM_CONTEXTS], backContext[NUM_CONTEXTS], - reliefContext[NUM_CONTEXTS]; - GC shadowContext[NUM_CONTEXTS], flatContext[NUM_CONTEXTS]; - XFontStruct *ButtonFont; + unsigned int magic; + int index; + + /* .fvwm2rc options or things set as a result of options */ + Resolution res; + Pixel backcolor[NUM_CONTEXTS], forecolor[NUM_CONTEXTS]; + Pixel hicolor[NUM_CONTEXTS], shadowcolor[NUM_CONTEXTS]; + GC hiContext[NUM_CONTEXTS], backContext[NUM_CONTEXTS], + reliefContext[NUM_CONTEXTS]; + GC shadowContext[NUM_CONTEXTS], flatContext[NUM_CONTEXTS]; + XFontStruct *ButtonFont; #ifdef MINI_ICONS - int draw_icons; + int draw_icons; #endif - int shaped; - StringList show; - StringList dontshow; - Binding *bindings[NUM_ACTIONS]; - char *fontname; - char *backColorName[NUM_CONTEXTS]; - char *foreColorName[NUM_CONTEXTS]; - ButtonState buttonState[NUM_CONTEXTS]; - char *geometry_str, *button_geometry_str; - char *titlename, *iconname; - char *formatstring; - NameType format_depend; - Uchar followFocus; - Uchar usewinlist; - SortType sort; - - /* X11 state */ - Window theWindow, theFrame; - long sizehints_flags; - int gravity; - int fontheight, fontwidth; - int win_title, win_border; - int off_x, off_y; - Uchar cursor_in_window; - Uchar window_up; - Uchar can_draw; /* = 0 until we get our first ConfigureNotify */ - - /* button state */ - int dirty_flags; - ManGeometry geometry, drawn_geometry; - Button *select_button, *focus_button; - Uchar window_mapped, drawn_mapping; + int shaped; + StringList show; + StringList dontshow; + Binding *bindings[NUM_ACTIONS]; + char *fontname; + char *backColorName[NUM_CONTEXTS]; + char *foreColorName[NUM_CONTEXTS]; + ButtonState buttonState[NUM_CONTEXTS]; + char *geometry_str, *button_geometry_str; + char *titlename, *iconname; + char *formatstring; + NameType format_depend; + Uchar followFocus; + Uchar usewinlist; + SortType sort; + + /* X11 state */ + Window theWindow, theFrame; + long sizehints_flags; + int gravity; + int fontheight, fontwidth; + int win_title, win_border; + int off_x, off_y; + Uchar cursor_in_window; + Uchar window_up; + Uchar can_draw; /* = 0 until we get our first ConfigureNotify */ + + /* button state */ + int dirty_flags; + ManGeometry geometry, drawn_geometry; + Button *select_button, *focus_button; + Uchar window_mapped, drawn_mapping; #ifdef SHAPE - ShapeState shape, drawn_shape; + ShapeState shape, drawn_shape; #endif - ButtonArray buttons; + ButtonArray buttons; - /* Fvwm state */ - int we_are_drawing, configures_expected; + /* Fvwm state */ + int we_are_drawing, configures_expected; } WinManager; #define MANAGER_EMPTY(man) ((man)->buttons.num_windows == 0) typedef struct { - Ulong desknum; - Ulong x, y; /* of the view window */ - long screenx, screeny; /* screen dimensions */ - WinManager *managers; - int num_managers; - int transient; - WinData *focus_win; - WinData *select_win; - int shapes_supported; - int got_window_list; + Ulong desknum; + Ulong x, y; /* of the view window */ + long screenx, screeny; /* screen dimensions */ + WinManager *managers; + int num_managers; + int transient; + WinData *focus_win; + WinData *select_win; + int shapes_supported; + int got_window_list; } GlobalData; typedef struct { - char *name; - ButtonState state; - char *forecolor[2]; /* 0 is mono, 1 is color */ - char *backcolor[2]; /* 0 is mono, 1 is color */ + char *name; + ButtonState state; + char *forecolor[2]; /* 0 is mono, 1 is color */ + char *backcolor[2]; /* 0 is mono, 1 is color */ } ContextDefaults; - extern char *contextNames[NUM_CONTEXTS]; extern GlobalData globals; @@ -344,30 +325,32 @@ extern int ModuleLen; extern ContextDefaults contextDefaults[]; extern void ReadFvwmPipe(void); -extern void *Malloc (size_t size); -extern void Free (void *p); -extern void ShutMeDown (int flag) __attribute__ ((__noreturn__)); -extern void DeadPipe (int nothing) __attribute__ ((__noreturn__)); +extern void *Malloc(size_t size); +extern void Free(void *p); +extern void ShutMeDown(int flag) __attribute__((__noreturn__)); +extern void DeadPipe(int nothing) __attribute__((__noreturn__)); extern void SendFvwmPipe(char *message, unsigned long window); -extern char *copy_string (char **target, char *src); - -extern void init_globals (void); -extern int allocate_managers (int num); - -extern WinData *new_windata (void); -extern void free_windata (WinData *p); -extern int check_win_complete (WinData *p); -extern WinManager *figure_win_manager (WinData *win, Uchar mask); -extern void init_winlists (void); -extern void delete_win_hashtab (WinData *win); -extern void insert_win_hashtab (WinData *win); -extern WinData *find_win_hashtab (Ulong id); -extern void walk_hashtab (void (*func)(void *)); -extern int accumulate_walk_hashtab (int (*func)(void *)); -extern void print_stringlist (StringList *list); -extern void add_to_stringlist (StringList *list, char *s); -extern void update_window_stuff (WinManager *man); -extern void print_managers (void); - -extern WinManager *find_windows_manager (Window win); -extern int win_in_viewport (WinData *win); +extern char *copy_string(char **target, char *src); + +extern void init_globals(void); +extern int allocate_managers(int num); + +extern WinData *new_windata(void); +extern void free_windata(WinData *p); +extern int check_win_complete(WinData *p); +extern WinManager *figure_win_manager(WinData *win, Uchar mask); +extern void init_winlists(void); +extern void delete_win_hashtab(WinData *win); +extern void insert_win_hashtab(WinData *win); +extern WinData *find_win_hashtab(Ulong id); +extern void walk_hashtab(void (*func)(void *)); +extern int accumulate_walk_hashtab(int (*func)(void *)); +extern void print_stringlist(StringList *list); +extern void add_to_stringlist(StringList *list, char *s); +extern void update_window_stuff(WinManager *man); +extern void print_managers(void); + +extern WinManager *find_windows_manager(Window win); +extern int win_in_viewport(WinData *win); + +#endif /* FVWMICONMAN_H */ Index: fvwm/modules/FvwmIconMan/debug.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/debug.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/debug.c --- fvwm/modules/FvwmIconMan/debug.c +++ fvwm/modules/FvwmIconMan/debug.c @@ -1,55 +1,54 @@ -#include #include +#include #include "FvwmIconMan.h" - #include "debuglevels.h" static char const rcsid[] = - "$Id: debug.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; + "$Id: debug.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; static FILE *console = NULL; void ConsoleMessage(const char *fmt, ...) { - va_list args; + va_list args; - assert(console != NULL); + assert(console != NULL); - fputs("FvwmIconMan: ", console); + fputs("FvwmIconMan: ", console); - va_start(args, fmt); - vfprintf(console, fmt, args); - va_end(args); + va_start(args, fmt); + vfprintf(console, fmt, args); + va_end(args); } int OpenConsole(const char *filenm) { - if (!filenm) - console = stderr; - else if ((console = fopen(filenm, "w")) == NULL) { - fprintf(stderr,"%s: cannot open %s\n", Module, filenm); - return 0; - } - - return 1; + if (!filenm) + console = stderr; + else if ((console = fopen(filenm, "w")) == NULL) { + fprintf(stderr, "%s: cannot open %s\n", Module, filenm); + return 0; + } + + return 1; } void ConsoleDebug(int flag, const char *fmt, ...) { - assert(console != NULL); + assert(console != NULL); #ifdef PRINT_DEBUG - if (flag) { - va_list args; - - va_start(args, fmt); - vfprintf(console, fmt, args); - fflush(console); - va_end(args); - } + if (flag) { + va_list args; + + va_start(args, fmt); + vfprintf(console, fmt, args); + fflush(console); + va_end(args); + } #endif } Index: fvwm/modules/FvwmIconMan/debug.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/debug.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/debug.h --- fvwm/modules/FvwmIconMan/debug.h +++ fvwm/modules/FvwmIconMan/debug.h @@ -2,21 +2,20 @@ #define IN_DEBUG_H #if 0 -# define PRINT_DEBUG +#define PRINT_DEBUG #endif #if 0 -# define OUTPUT_FILE "/dev/console" +#define OUTPUT_FILE "/dev/console" #else -# define OUTPUT_FILE NULL +#define OUTPUT_FILE NULL #endif - extern int OpenConsole(const char *filenm); extern void ConsoleMessage(const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); + __attribute__((__format__(__printf__, 1, 2))); extern void ConsoleDebug(int flag, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + __attribute__((__format__(__printf__, 2, 3))); extern int CORE, FUNCTIONS, X11, FVWM, CONFIG, WINLIST, MEM; Index: fvwm/modules/FvwmIconMan/functions.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/functions.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/functions.c --- fvwm/modules/FvwmIconMan/functions.c +++ fvwm/modules/FvwmIconMan/functions.c @@ -3,517 +3,545 @@ #include "xmanager.h" static char const rcsid[] = - "$Id: functions.c,v 1.2 2021/01/24 09:21:21 matthieu Exp $"; + "$Id: functions.c,v 1.2 2021/01/24 09:21:21 matthieu Exp $"; -static Button *get_select_button (void); +static Button *get_select_button(void); static struct { - Button *current_button; - Function *fp; + Button *current_button; + Function *fp; } function_context; -static void init_function_context (Function *func) +static void +init_function_context(Function *func) { - function_context.current_button = get_select_button(); - function_context.fp = func; + function_context.current_button = get_select_button(); + function_context.fp = func; } -void run_function_list (Function *func) +void +run_function_list(Function *func) { - init_function_context (func); - - while (function_context.fp) { - function_context.fp->func (function_context.fp->numargs, - function_context.fp->args); - if (function_context.fp) - function_context.fp = function_context.fp->next; - } + init_function_context(func); + + while (function_context.fp) { + function_context.fp->func( + function_context.fp->numargs, function_context.fp->args); + if (function_context.fp) + function_context.fp = function_context.fp->next; + } } -static Button *get_select_button (void) +static Button * +get_select_button(void) { - if (globals.select_win) - return globals.select_win->button; - return NULL; + if (globals.select_win) + return globals.select_win->button; + return NULL; } -static Button *get_focus_button (void) +static Button * +get_focus_button(void) { - if (globals.focus_win) - return globals.focus_win->button; - return NULL; + if (globals.focus_win) + return globals.focus_win->button; + return NULL; } -static WinManager *get_current_man (void) +static WinManager * +get_current_man(void) { - Button *b = function_context.current_button; + Button *b = function_context.current_button; - if (globals.num_managers==1) - return globals.managers; - if (b && b->drawn_state.win) - return b->drawn_state.win->manager; - return NULL; + if (globals.num_managers == 1) + return globals.managers; + if (b && b->drawn_state.win) + return b->drawn_state.win->manager; + return NULL; } -static WinData *get_current_win (void) +static WinData * +get_current_win(void) { - Button *b = function_context.current_button; + Button *b = function_context.current_button; - if (b && b->drawn_state.win) - return b->drawn_state.win; - return NULL; + if (b && b->drawn_state.win) + return b->drawn_state.win; + return NULL; } -static Button *get_current_button (void) +static Button * +get_current_button(void) { - return function_context.current_button; + return function_context.current_button; } -static Button *button_move (ButtonValue *bv) +static Button * +button_move(ButtonValue *bv) { - Button *b = NULL, *cur; - WinManager *man; - int i; - - cur = get_current_button(); - - switch (bv->base) { - case NoButton: - ConsoleMessage ("gotobutton: need a button to change to\n"); - return cur; - - case SelectButton: - b = get_select_button(); - break; - - case FocusButton: - b = get_focus_button(); - break; - - case AbsoluteButton: - man = get_current_man(); - if (man && man->buttons.num_windows > 0) { - i = bv->offset % man->buttons.num_windows; - if (i < 0) - i += man->buttons.num_windows; - b = man->buttons.buttons[i]; - } - break; - - default: - man = get_current_man(); - if (!cur) { - ConsoleDebug (FUNCTIONS, "\tno current button, skipping\n"); - return NULL; - } - - switch (bv->base) { - case UpButton: - b = button_above (man, cur); - break; - - case DownButton: - b = button_below (man, cur); - break; - - case LeftButton: - b = button_left (man, cur); - break; - - case RightButton: - b = button_right (man, cur); - break; - - case NextButton: - b = button_next (man, cur); - break; - - case PrevButton: - b = button_prev (man, cur); - break; - - default: - ConsoleMessage ("Internal error in gotobutton\n"); - break; - } - } - - return b; + Button *b = NULL, *cur; + WinManager *man; + int i; + + cur = get_current_button(); + + switch (bv->base) { + case NoButton: + ConsoleMessage("gotobutton: need a button to change to\n"); + return cur; + + case SelectButton: + b = get_select_button(); + break; + + case FocusButton: + b = get_focus_button(); + break; + + case AbsoluteButton: + man = get_current_man(); + if (man && man->buttons.num_windows > 0) { + i = bv->offset % man->buttons.num_windows; + if (i < 0) + i += man->buttons.num_windows; + b = man->buttons.buttons[i]; + } + break; + + default: + man = get_current_man(); + if (!cur) { + ConsoleDebug( + FUNCTIONS, "\tno current button, skipping\n"); + return NULL; + } + + switch (bv->base) { + case UpButton: + b = button_above(man, cur); + break; + + case DownButton: + b = button_below(man, cur); + break; + + case LeftButton: + b = button_left(man, cur); + break; + + case RightButton: + b = button_right(man, cur); + break; + + case NextButton: + b = button_next(man, cur); + break; + + case PrevButton: + b = button_prev(man, cur); + break; + + default: + ConsoleMessage("Internal error in gotobutton\n"); + break; + } + } + + return b; } -int builtin_gotobutton (int numargs, BuiltinArg *args) +int +builtin_gotobutton(int numargs, BuiltinArg *args) { - Button *b; - ButtonValue *bv; + Button *b; + ButtonValue *bv; - ConsoleDebug (FUNCTIONS, "gotobutton: "); - print_args (numargs, args); + ConsoleDebug(FUNCTIONS, "gotobutton: "); + print_args(numargs, args); - bv = &args[0].value.button_value; + bv = &args[0].value.button_value; - b = button_move (bv); + b = button_move(bv); - if (b) - function_context.current_button = b; + if (b) + function_context.current_button = b; - return 0; + return 0; } -int builtin_gotomanager (int numargs, BuiltinArg *args) +int +builtin_gotomanager(int numargs, BuiltinArg *args) { - ButtonValue *bv; - WinManager *man, *new; - int i; + ButtonValue *bv; + WinManager *man, *new; + int i; - ConsoleDebug (FUNCTIONS, "gotomanager: "); - print_args (numargs, args); + ConsoleDebug(FUNCTIONS, "gotomanager: "); + print_args(numargs, args); - bv = &args[0].value.button_value; + bv = &args[0].value.button_value; - new = man = get_current_man(); + new = man = get_current_man(); - switch (bv->base) { - case NoButton: - ConsoleMessage ("gotomanager: need a manager argument\n"); - return 1; + switch (bv->base) { + case NoButton: + ConsoleMessage("gotomanager: need a manager argument\n"); + return 1; - case SelectButton: - case FocusButton: - ConsoleMessage ("gotomanger: \"select\" or \"focus\" does not specify" + case SelectButton: + case FocusButton: + ConsoleMessage( + "gotomanger: \"select\" or \"focus\" does not specify" " a manager\n"); - break; - - case AbsoluteButton: - { - /* Now we find the manager modulo the VISIBLE managers */ - static WinManager **wa = NULL; - int i, num_mapped, n; - - n = globals.num_managers; - if (n) { - if (wa == NULL) { - wa = (WinManager **)safemalloc (n * sizeof (WinManager *)); - } - for (i = 0, num_mapped = 0; i < n; i++) { - if (globals.managers[i].buttons.num_windows > 0 && - globals.managers[i].window_mapped) { - wa[num_mapped++] = &globals.managers[i]; + break; + + case AbsoluteButton: { + /* Now we find the manager modulo the VISIBLE managers */ + static WinManager **wa = NULL; + int i, num_mapped, n; + + n = globals.num_managers; + if (n) { + if (wa == NULL) { + wa = (WinManager **)xmalloc( + n * sizeof(WinManager *)); + } + for (i = 0, num_mapped = 0; i < n; i++) { + if (globals.managers[i].buttons.num_windows > + 0 && + globals.managers[i].window_mapped) { + wa[num_mapped++] = &globals.managers[i]; + } + } + if (num_mapped) { + i = bv->offset % num_mapped; + if (i < 0) + i += num_mapped; + new = wa[i]; + } else { + new = NULL; + } + } + } + break; + + case NextButton: + if (man) { + for (i = man->index + 1, new = man + 1; + i < globals.num_managers && new->buttons + .num_windows == + 0; + i++, new++) + ; + if (i == globals.num_managers) + new = man; + } + break; + + case PrevButton: + if (man) { + for (i = man->index - 1, new = man - 1; + i > -1 && new->buttons.num_windows == 0; + i--, new--) + ; + if (i == -1) + new = man; + } + break; + + default: + ConsoleMessage("gotomanager: bad argument\n"); + break; + } + + if (new && new != man && new->buttons.num_windows > 0) { + function_context.current_button = new->buttons.buttons[0]; } - } - if (num_mapped) { - i = bv->offset % num_mapped; - if (i < 0) - i += num_mapped; - new = wa[i]; - } - else { - new = NULL; - } - } - } - break; - - case NextButton: - if (man) { - for (i = man->index + 1, new = man + 1; - i < globals.num_managers && new->buttons.num_windows == 0; - i++, new++) - ; - if (i == globals.num_managers) - new = man; - } - break; - - case PrevButton: - if (man) { - for (i = man->index - 1, new = man - 1; - i > -1 && new->buttons.num_windows == 0; - i--, new--) - ; - if (i == -1) - new = man; - } - break; - - default: - ConsoleMessage ("gotomanager: bad argument\n"); - break; - } - - if (new && new != man && new->buttons.num_windows > 0) { - function_context.current_button = new->buttons.buttons[0]; - } - - return 0; -} + return 0; +} -int builtin_select (int numargs, BuiltinArg *args) +int +builtin_select(int numargs, BuiltinArg *args) { - WinManager *man = get_current_man(); - if (man) { - move_highlight (man, get_current_button()); - if (get_current_button()) - run_binding (man, SELECT); - } - return 0; + WinManager *man = get_current_man(); + if (man) { + move_highlight(man, get_current_button()); + if (get_current_button()) + run_binding(man, SELECT); + } + return 0; } -int builtin_sendcommand (int numargs, BuiltinArg *args) +int +builtin_sendcommand(int numargs, BuiltinArg *args) { - WinData *win = get_current_win(); + WinData *win = get_current_win(); - if (!win) { - return 0; - } + if (!win) { + return 0; + } - SendFvwmPipe (args[0].value.string_value, win->app_id); + SendFvwmPipe(args[0].value.string_value, win->app_id); - return 0; + return 0; } -int builtin_printdebug (int numargs, BuiltinArg *args) +int +builtin_printdebug(int numargs, BuiltinArg *args) { - int i; - - for (i = 0; i < globals.num_managers; i++) { - ConsoleDebug (FUNCTIONS, "Manager %d\n---------\n", i); - ConsoleDebug (FUNCTIONS, "Keys:\n"); - print_bindings (globals.managers[i].bindings[KEYPRESS]); - ConsoleDebug (FUNCTIONS, "Mice:\n"); - print_bindings (globals.managers[i].bindings[MOUSE]); - ConsoleDebug (FUNCTIONS, "Select:\n"); - print_bindings (globals.managers[i].bindings[SELECT]); - ConsoleDebug (FUNCTIONS, "\n"); - } - - return 0; + int i; + + for (i = 0; i < globals.num_managers; i++) { + ConsoleDebug(FUNCTIONS, "Manager %d\n---------\n", i); + ConsoleDebug(FUNCTIONS, "Keys:\n"); + print_bindings(globals.managers[i].bindings[KEYPRESS]); + ConsoleDebug(FUNCTIONS, "Mice:\n"); + print_bindings(globals.managers[i].bindings[MOUSE]); + ConsoleDebug(FUNCTIONS, "Select:\n"); + print_bindings(globals.managers[i].bindings[SELECT]); + ConsoleDebug(FUNCTIONS, "\n"); + } + + return 0; } -int builtin_quit (int numargs, BuiltinArg *args) +int +builtin_quit(int numargs, BuiltinArg *args) { - ConsoleDebug (FUNCTIONS, "quit: "); - print_args (numargs, args); - ShutMeDown (0); - return 0; + ConsoleDebug(FUNCTIONS, "quit: "); + print_args(numargs, args); + ShutMeDown(0); + return 0; } -static void do_jmp (int off) +static void +do_jmp(int off) { - int i; - ConsoleDebug (FUNCTIONS, "jmp: %d\n", off); - - if (off < 0) { - ConsoleMessage ("Can't have a negative relative jump offset\n"); - return; - } - for (i = 0; i < off; i++) { - if (function_context.fp) - function_context.fp = function_context.fp->next; - } + int i; + ConsoleDebug(FUNCTIONS, "jmp: %d\n", off); + + if (off < 0) { + ConsoleMessage("Can't have a negative relative jump offset\n"); + return; + } + for (i = 0; i < off; i++) { + if (function_context.fp) + function_context.fp = function_context.fp->next; + } } -static int eval_if (ButtonValue *bv) +static int +eval_if(ButtonValue *bv) { - Button *cur; - WinManager *man; - - switch (bv->base) { - case NoButton: - ConsoleMessage ("Internal error in eval_if: 1\n"); - break; - - case SelectButton: - if (get_select_button()) - return 1; - break; - - case FocusButton: - if (get_focus_button()) - return 1; - break; - - case AbsoluteButton: - if (bv->offset != 0) - return 1; - break; - - default: - cur = get_current_button(); - man = get_current_man(); - if (!cur || !man) { - return 0; - } - - switch (bv->base) { - case UpButton: - return (button_above (man, cur) != cur); - - case DownButton: - return (button_below (man, cur) != cur); - - case LeftButton: - return (button_left (man, cur) != cur); - - case RightButton: - return (button_right (man, cur) != cur); - - case NextButton: - return (button_next (man, cur) != cur); - - case PrevButton: - return (button_prev (man, cur) != cur); - - default: - ConsoleMessage ("Internal error in eval_if: 2\n"); - break; - } - } - - return 0; + Button *cur; + WinManager *man; + + switch (bv->base) { + case NoButton: + ConsoleMessage("Internal error in eval_if: 1\n"); + break; + + case SelectButton: + if (get_select_button()) + return 1; + break; + + case FocusButton: + if (get_focus_button()) + return 1; + break; + + case AbsoluteButton: + if (bv->offset != 0) + return 1; + break; + + default: + cur = get_current_button(); + man = get_current_man(); + if (!cur || !man) { + return 0; + } + + switch (bv->base) { + case UpButton: + return (button_above(man, cur) != cur); + + case DownButton: + return (button_below(man, cur) != cur); + + case LeftButton: + return (button_left(man, cur) != cur); + + case RightButton: + return (button_right(man, cur) != cur); + + case NextButton: + return (button_next(man, cur) != cur); + + case PrevButton: + return (button_prev(man, cur) != cur); + + default: + ConsoleMessage("Internal error in eval_if: 2\n"); + break; + } + } + + return 0; } -int builtin_bif (int numargs, BuiltinArg *args) +int +builtin_bif(int numargs, BuiltinArg *args) { - int off = args[1].value.int_value; - ConsoleDebug (FUNCTIONS, "bif: off = %d\n", off); + int off = args[1].value.int_value; + ConsoleDebug(FUNCTIONS, "bif: off = %d\n", off); - if (eval_if (&args[0].value.button_value)) { - do_jmp (off); - } + if (eval_if(&args[0].value.button_value)) { + do_jmp(off); + } - return 0; + return 0; } -int builtin_bifn (int numargs, BuiltinArg *args) +int +builtin_bifn(int numargs, BuiltinArg *args) { - int off = args[1].value.int_value; - ConsoleDebug (FUNCTIONS, "bifn: off = %d\n", off); + int off = args[1].value.int_value; + ConsoleDebug(FUNCTIONS, "bifn: off = %d\n", off); - if (eval_if (&args[0].value.button_value) == 0) { - do_jmp (off); - } + if (eval_if(&args[0].value.button_value) == 0) { + do_jmp(off); + } - return 0; + return 0; } -int builtin_jmp (int numargs, BuiltinArg *args) +int +builtin_jmp(int numargs, BuiltinArg *args) { - int off = args[0].value.int_value; - ConsoleDebug (FUNCTIONS, "jmp: off = %d\n", off); + int off = args[0].value.int_value; + ConsoleDebug(FUNCTIONS, "jmp: off = %d\n", off); - do_jmp (off); - return 0; + do_jmp(off); + return 0; } -int builtin_ret (int numargs, BuiltinArg *args) +int +builtin_ret(int numargs, BuiltinArg *args) { - function_context.fp = NULL; - return 0; + function_context.fp = NULL; + return 0; } -int builtin_print (int numargs, BuiltinArg *args) +int +builtin_print(int numargs, BuiltinArg *args) { - char *s; + char *s; - ConsoleDebug (FUNCTIONS, "print: %s\n", args[0].value.string_value); + ConsoleDebug(FUNCTIONS, "print: %s\n", args[0].value.string_value); - s = args[0].value.string_value; - if (strlen (s) > 250) { - ConsoleMessage ("String too long\n"); - } - else { - ConsoleMessage ("%s\n", s); - } + s = args[0].value.string_value; + if (strlen(s) > 250) { + ConsoleMessage("String too long\n"); + } else { + ConsoleMessage("%s\n", s); + } - return 0; + return 0; } -int builtin_searchforward (int numargs, BuiltinArg *args) +int +builtin_searchforward(int numargs, BuiltinArg *args) { - char *s; - Button *b, *cur; - WinManager *man; - - s = args[0].value.string_value; - - ConsoleDebug (FUNCTIONS, "searchforward: %s\n", s); - - cur = get_current_button(); - man = get_current_man(); - b = cur; - if (cur) { - while (1) { - if (cur->drawn_state.display_string && - matchWildcards (s, cur->drawn_state.display_string)) - break; - b = button_next (man, cur); - if (b == cur) { - cur = NULL; - break; - } - cur = b; - } - } - if (cur) - function_context.current_button = cur; - - return 0; -} + char *s; + Button *b, *cur; + WinManager *man; + + s = args[0].value.string_value; + + ConsoleDebug(FUNCTIONS, "searchforward: %s\n", s); + + cur = get_current_button(); + man = get_current_man(); + b = cur; + if (cur) { + while (1) { + if (cur->drawn_state.display_string && + matchWildcards(s, cur->drawn_state.display_string)) + break; + b = button_next(man, cur); + if (b == cur) { + cur = NULL; + break; + } + cur = b; + } + } + if (cur) + function_context.current_button = cur; -int builtin_searchback (int numargs, BuiltinArg *args) -{ - char *s; - Button *b, *cur; - WinManager *man; - - s = args[0].value.string_value; - - ConsoleDebug (FUNCTIONS, "searchback: %s\n", s); - - cur = get_current_button(); - man = get_current_man(); - b = cur; - if (cur) { - while (1) { - if (cur->drawn_state.display_string && - matchWildcards (s, cur->drawn_state.display_string)) - break; - b = button_prev (man, cur); - if (b == cur) { - cur = NULL; - break; - } - cur = b; - } - } - if (cur) - function_context.current_button = cur; - - return 0; + return 0; } -int builtin_warp (int numargs, BuiltinArg *args) +int +builtin_searchback(int numargs, BuiltinArg *args) { - Button *cur; - WinManager *man; - int x, y; + char *s; + Button *b, *cur; + WinManager *man; + + s = args[0].value.string_value; + + ConsoleDebug(FUNCTIONS, "searchback: %s\n", s); + + cur = get_current_button(); + man = get_current_man(); + b = cur; + if (cur) { + while (1) { + if (cur->drawn_state.display_string && + matchWildcards(s, cur->drawn_state.display_string)) + break; + b = button_prev(man, cur); + if (b == cur) { + cur = NULL; + break; + } + cur = b; + } + } + if (cur) + function_context.current_button = cur; - ConsoleDebug (FUNCTIONS, "warp\n"); + return 0; +} - cur = get_current_button(); - if (cur) { - man = get_current_man(); - x = cur->x + cur->w / 2; - y = cur->y + cur->h / 2; - XWarpPointer (theDisplay, None, man->theWindow, 0, 0, 0, 0, x, y); - } +int +builtin_warp(int numargs, BuiltinArg *args) +{ + Button *cur; + WinManager *man; + int x, y; + + ConsoleDebug(FUNCTIONS, "warp\n"); + + cur = get_current_button(); + if (cur) { + man = get_current_man(); + x = cur->x + cur->w / 2; + y = cur->y + cur->h / 2; + XWarpPointer( + theDisplay, None, man->theWindow, 0, 0, 0, 0, x, y); + } - return 0; + return 0; } -int builtin_refresh (int numargs, BuiltinArg *args) +int +builtin_refresh(int numargs, BuiltinArg *args) { - draw_managers(); - return 0; + draw_managers(); + return 0; } Index: fvwm/modules/FvwmIconMan/fvwm.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/fvwm.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/fvwm.c --- fvwm/modules/FvwmIconMan/fvwm.c +++ fvwm/modules/FvwmIconMan/fvwm.c @@ -1,575 +1,595 @@ -#include "config.h" +#include "../fvwm/fvwm.h" +#include "../fvwm/module.h" #include "FvwmIconMan.h" +#include "config.h" #include "x.h" #include "xmanager.h" -#include "../fvwm/fvwm.h" -#include "../fvwm/module.h" - static char const rcsid[] = - "$Id: fvwm.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; + "$Id: fvwm.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; typedef struct { - Ulong paging_enabled; + Ulong paging_enabled; } m_toggle_paging_data; typedef struct { - Ulong desknum; + Ulong desknum; } m_new_desk_data; typedef struct { - Ulong app_id; - Ulong frame_id; - Ulong dbase_entry; - Ulong xpos; - Ulong ypos; - Ulong width; - Ulong height; - Ulong desknum; - Ulong windows_flags; - Ulong window_title_height; - Ulong window_border_width; - Ulong window_base_width; - Ulong window_base_height; - Ulong window_resize_width_inc; - Ulong window_resize_height_inc; - Ulong window_min_width; - Ulong window_min_height; - Ulong window_max_width_inc; - Ulong window_max_height_inc; - Ulong icon_label_id; - Ulong icon_pixmap_id; - Ulong window_gravity; + Ulong app_id; + Ulong frame_id; + Ulong dbase_entry; + Ulong xpos; + Ulong ypos; + Ulong width; + Ulong height; + Ulong desknum; + Ulong windows_flags; + Ulong window_title_height; + Ulong window_border_width; + Ulong window_base_width; + Ulong window_base_height; + Ulong window_resize_width_inc; + Ulong window_resize_height_inc; + Ulong window_min_width; + Ulong window_min_height; + Ulong window_max_width_inc; + Ulong window_max_height_inc; + Ulong icon_label_id; + Ulong icon_pixmap_id; + Ulong window_gravity; } m_add_config_data; typedef struct { - Ulong x, y, desknum; + Ulong x, y, desknum; } m_new_page_data; typedef struct { - Ulong app_id, frame_id, dbase_entry; + Ulong app_id, frame_id, dbase_entry; } m_minimal_data; typedef struct { - Ulong app_id, frame_id, dbase_entry; - Ulong xpos, ypos, icon_width, icon_height; + Ulong app_id, frame_id, dbase_entry; + Ulong xpos, ypos, icon_width, icon_height; } m_icon_data; typedef struct { - Ulong app_id, frame_id, dbase_entry; - union { - Ulong name_long[1]; - Uchar name[4]; - } name; + Ulong app_id, frame_id, dbase_entry; + union { + Ulong name_long[1]; + Uchar name[4]; + } name; } m_name_data; #ifdef MINI_ICONS typedef struct { - Ulong app_id, frame_id, dbase_entry; - Ulong width, height, depth, picture, mask; - union { - Ulong name_long[1]; - Uchar name[4]; - } name; + Ulong app_id, frame_id, dbase_entry; + Ulong width, height, depth, picture, mask; + union { + Ulong name_long[1]; + Uchar name[4]; + } name; } m_mini_icon_data; #endif typedef struct { - Ulong start, type, len, time /* in fvwm 2 only */; + Ulong start, type, len, time /* in fvwm 2 only */; } FvwmPacketHeader; typedef union { - m_toggle_paging_data toggle_paging_data; - m_new_desk_data new_desk_data; - m_add_config_data add_config_data; - m_new_page_data new_page_data; - m_minimal_data minimal_data; - m_icon_data icon_data; - m_name_data name_data; + m_toggle_paging_data toggle_paging_data; + m_new_desk_data new_desk_data; + m_add_config_data add_config_data; + m_new_page_data new_page_data; + m_minimal_data minimal_data; + m_icon_data icon_data; + m_name_data name_data; #ifdef MINI_ICONS - m_mini_icon_data mini_icon_data; + m_mini_icon_data mini_icon_data; #endif } FvwmPacketBody; /* only used by count_nonsticky_in_hashtab */ static WinManager *the_manager; -static int count_nonsticky_in_hashtab (void *arg) +static int +count_nonsticky_in_hashtab(void *arg) { - WinData *win = (WinData *)arg; - WinManager *man = the_manager; + WinData *win = (WinData *)arg; + WinManager *man = the_manager; - if (!(win->fvwm_flags & STICKY) && win->complete && win->manager == man) - return 1; - return 0; + if (!(win->fvwm_flags & STICKY) && win->complete && win->manager == man) + return 1; + return 0; } -static void set_draw_mode (WinManager *man, int flag) +static void +set_draw_mode(WinManager *man, int flag) { - int num; - - if (!man) - return; - - if (man->we_are_drawing == 0 && flag) { - draw_manager (man); - } - else if (man->we_are_drawing && !flag) { - the_manager = man; - num = accumulate_walk_hashtab (count_nonsticky_in_hashtab); - ConsoleDebug (FVWM, "SetDrawMode on 0x%lx, num = %d\n", - (unsigned long)man, num); - - if (num == 0) - return; - man->configures_expected = num; - } - man->we_are_drawing = flag; + int num; + + if (!man) + return; + + if (man->we_are_drawing == 0 && flag) { + draw_manager(man); + } else if (man->we_are_drawing && !flag) { + the_manager = man; + num = accumulate_walk_hashtab(count_nonsticky_in_hashtab); + ConsoleDebug(FVWM, "SetDrawMode on 0x%lx, num = %d\n", + (unsigned long)man, num); + + if (num == 0) + return; + man->configures_expected = num; + } + man->we_are_drawing = flag; } -static int drawing (WinManager *man) +static int +drawing(WinManager *man) { - if (!man) - return 1; + if (!man) + return 1; - return man->we_are_drawing; + return man->we_are_drawing; } -static void got_configure (WinManager *man) +static void +got_configure(WinManager *man) { - if (man && !man->we_are_drawing) { - man->configures_expected--; - ConsoleDebug (FVWM, "got_configure on 0x%lx, num_expected now = %d\n", - (unsigned long) man, man->configures_expected); - if (man->configures_expected <= 0) - set_draw_mode (man, 1); - } + if (man && !man->we_are_drawing) { + man->configures_expected--; + ConsoleDebug(FVWM, + "got_configure on 0x%lx, num_expected now = %d\n", + (unsigned long)man, man->configures_expected); + if (man->configures_expected <= 0) + set_draw_mode(man, 1); + } } -int win_in_viewport (WinData *win) +int +win_in_viewport(WinData *win) { - WinManager *manager = win->manager; - int flag = 0; - - assert (manager); - - switch (manager->res) { - case SHOW_GLOBAL: - flag = 1; - break; - - case SHOW_DESKTOP: - if ((win->fvwm_flags & STICKY) || win->desknum == globals.desknum) - flag = 1; - break; - - case SHOW_PAGE: - if (win->fvwm_flags & STICKY) { - flag = 1; - } else if (win->desknum == globals.desknum) { - /* win and screen intersect if they are not disjoint in x and y */ - flag = RECTANGLES_INTERSECT (win->x, win->y, win->width, win->height, - 0, 0, globals.screenx, globals.screeny); - } - break; - } - return flag; + WinManager *manager = win->manager; + int flag = 0; + + assert(manager); + + switch (manager->res) { + case SHOW_GLOBAL: + flag = 1; + break; + + case SHOW_DESKTOP: + if ((win->fvwm_flags & STICKY) || + win->desknum == globals.desknum) + flag = 1; + break; + + case SHOW_PAGE: + if (win->fvwm_flags & STICKY) { + flag = 1; + } else if (win->desknum == globals.desknum) { + /* win and screen intersect if they are not disjoint in + * x and y */ + flag = RECTANGLES_INTERSECT(win->x, win->y, win->width, + win->height, 0, 0, globals.screenx, + globals.screeny); + } + break; + } + return flag; } - -static WinData *id_to_win (Ulong id) +static WinData * +id_to_win(Ulong id) { - WinData *win; - win = find_win_hashtab (id); - if (win == NULL) { - win = new_windata (); - win->app_id = id; - win->app_id_set = 1; - insert_win_hashtab (win); - } - return win; + WinData *win; + win = find_win_hashtab(id); + if (win == NULL) { + win = new_windata(); + win->app_id = id; + win->app_id_set = 1; + insert_win_hashtab(win); + } + return win; } -static void set_win_configuration (WinData *win, FvwmPacketBody *body) +static void +set_win_configuration(WinData *win, FvwmPacketBody *body) { - win->desknum = body->add_config_data.desknum; - win->x = body->add_config_data.xpos; - win->y = body->add_config_data.ypos; - win->width = body->add_config_data.width; - win->height = body->add_config_data.height; - win->geometry_set = 1; - win->fvwm_flags = body->add_config_data.windows_flags; + win->desknum = body->add_config_data.desknum; + win->x = body->add_config_data.xpos; + win->y = body->add_config_data.ypos; + win->width = body->add_config_data.width; + win->height = body->add_config_data.height; + win->geometry_set = 1; + win->fvwm_flags = body->add_config_data.windows_flags; } -static void configure_window (FvwmPacketBody *body) +static void +configure_window(FvwmPacketBody *body) { - Ulong app_id = body->add_config_data.app_id; - WinData *win; - ConsoleDebug (FVWM, "configure_window: %ld\n", app_id); + Ulong app_id = body->add_config_data.app_id; + WinData *win; + ConsoleDebug(FVWM, "configure_window: %ld\n", app_id); - win = id_to_win (app_id); + win = id_to_win(app_id); - set_win_configuration (win, body); + set_win_configuration(win, body); - check_win_complete (win); - check_in_window (win); - got_configure (win->manager); + check_win_complete(win); + check_in_window(win); + got_configure(win->manager); } -static void focus_change (FvwmPacketBody *body) +static void +focus_change(FvwmPacketBody *body) { - Ulong app_id = body->minimal_data.app_id; - WinData *win = id_to_win (app_id); - - ConsoleDebug (FVWM, "Focus Change\n"); - ConsoleDebug (FVWM, "\tID: %ld\n", app_id); - - if (globals.focus_win) { - del_win_state (globals.focus_win, FOCUS_CONTEXT); - if (globals.focus_win->manager && globals.focus_win->manager->focus_button) - globals.focus_win->manager->focus_button = NULL; - globals.focus_win = NULL; - } - - - if (win->complete && - win->button && - win->manager && - win->manager->window_up && - win->manager->followFocus) { - win->manager->focus_button = win->button; - add_win_state (win, FOCUS_CONTEXT); - } - - globals.focus_win = win; - ConsoleDebug (FVWM, "leaving focus_change\n"); + Ulong app_id = body->minimal_data.app_id; + WinData *win = id_to_win(app_id); + + ConsoleDebug(FVWM, "Focus Change\n"); + ConsoleDebug(FVWM, "\tID: %ld\n", app_id); + + if (globals.focus_win) { + del_win_state(globals.focus_win, FOCUS_CONTEXT); + if (globals.focus_win->manager && + globals.focus_win->manager->focus_button) + globals.focus_win->manager->focus_button = NULL; + globals.focus_win = NULL; + } + + if (win->complete && win->button && win->manager && + win->manager->window_up && win->manager->followFocus) { + win->manager->focus_button = win->button; + add_win_state(win, FOCUS_CONTEXT); + } + + globals.focus_win = win; + ConsoleDebug(FVWM, "leaving focus_change\n"); } -static void res_name (FvwmPacketBody *body) +static void +res_name(FvwmPacketBody *body) { - Ulong app_id = body->name_data.app_id; - Uchar *name = body->name_data.name.name; - WinData *win; + Ulong app_id = body->name_data.app_id; + Uchar *name = body->name_data.name.name; + WinData *win; - ConsoleDebug (FVWM, "In res_name\n"); + ConsoleDebug(FVWM, "In res_name\n"); - win = id_to_win (app_id); + win = id_to_win(app_id); - copy_string (&win->resname, (char *)name); - change_windows_manager (win); + copy_string(&win->resname, (char *)name); + change_windows_manager(win); - ConsoleDebug (FVWM, "Exiting res_name\n"); + ConsoleDebug(FVWM, "Exiting res_name\n"); } -static void class_name (FvwmPacketBody *body) +static void +class_name(FvwmPacketBody *body) { - Ulong app_id = body->name_data.app_id; - Uchar *name = body->name_data.name.name; - WinData *win; + Ulong app_id = body->name_data.app_id; + Uchar *name = body->name_data.name.name; + WinData *win; - ConsoleDebug (FVWM, "In class_name\n"); + ConsoleDebug(FVWM, "In class_name\n"); - win = id_to_win (app_id); + win = id_to_win(app_id); - copy_string (&win->classname, (char *)name); - change_windows_manager (win); + copy_string(&win->classname, (char *)name); + change_windows_manager(win); - ConsoleDebug (FVWM, "Exiting class_name\n"); + ConsoleDebug(FVWM, "Exiting class_name\n"); } -static void icon_name (FvwmPacketBody *body) +static void +icon_name(FvwmPacketBody *body) { - WinData *win; - Ulong app_id; - Uchar *name = body->name_data.name.name; + WinData *win; + Ulong app_id; + Uchar *name = body->name_data.name.name; - ConsoleDebug (FVWM, "In icon_name\n"); + ConsoleDebug(FVWM, "In icon_name\n"); - app_id = body->name_data.app_id; + app_id = body->name_data.app_id; - win = id_to_win (app_id); + win = id_to_win(app_id); - if (win->iconname && !strcmp (win->iconname, name)) { - ConsoleDebug (FVWM, "No icon change: %s %s\n", win->iconname, name); - return; - } + if (win->iconname && !strcmp(win->iconname, name)) { + ConsoleDebug( + FVWM, "No icon change: %s %s\n", win->iconname, name); + return; + } - copy_string (&win->iconname, (char *)name); - ConsoleDebug (FVWM, "new icon name: %s\n", win->iconname); - if (change_windows_manager (win) == 0 && win->button && - (win->manager->format_depend & ICON_NAME)) { - if (win->manager->sort) { - resort_windows_button (win); - } - } + copy_string(&win->iconname, (char *)name); + ConsoleDebug(FVWM, "new icon name: %s\n", win->iconname); + if (change_windows_manager(win) == 0 && win->button && + (win->manager->format_depend & ICON_NAME)) { + if (win->manager->sort) { + resort_windows_button(win); + } + } - ConsoleDebug (FVWM, "Exiting icon_name\n"); + ConsoleDebug(FVWM, "Exiting icon_name\n"); } -static void window_name (FvwmPacketBody *body) +static void +window_name(FvwmPacketBody *body) { - WinData *win; - Ulong app_id; - Uchar *name = body->name_data.name.name; - - ConsoleDebug (FVWM, "In window_name\n"); - - app_id = body->name_data.app_id; - - win = id_to_win (app_id); - - /* This is necessary because bash seems to update the window title on - every keystroke regardless of whether anything changes */ - if (win->titlename && !strcmp (win->titlename, name)) { - ConsoleDebug (FVWM, "No name change: %s %s\n", win->titlename, name); - return; - } - - copy_string (&win->titlename, (char *)name); - if (change_windows_manager (win) == 0 && win->button && - (win->manager->format_depend & TITLE_NAME)) { - if (win->manager->sort) { - resort_windows_button (win); - } - } - ConsoleDebug (FVWM, "Exiting window_name\n"); + WinData *win; + Ulong app_id; + Uchar *name = body->name_data.name.name; + + ConsoleDebug(FVWM, "In window_name\n"); + + app_id = body->name_data.app_id; + + win = id_to_win(app_id); + + /* This is necessary because bash seems to update the window title on + every keystroke regardless of whether anything changes */ + if (win->titlename && !strcmp(win->titlename, name)) { + ConsoleDebug( + FVWM, "No name change: %s %s\n", win->titlename, name); + return; + } + + copy_string(&win->titlename, (char *)name); + if (change_windows_manager(win) == 0 && win->button && + (win->manager->format_depend & TITLE_NAME)) { + if (win->manager->sort) { + resort_windows_button(win); + } + } + ConsoleDebug(FVWM, "Exiting window_name\n"); } -static void new_window (FvwmPacketBody *body) +static void +new_window(FvwmPacketBody *body) { - WinData *win; - - win = new_windata(); - if (!(body->add_config_data.windows_flags & TRANSIENT)) { - win->app_id = body->add_config_data.app_id; - win->app_id_set = 1; - set_win_configuration (win, body); - - insert_win_hashtab (win); - check_win_complete (win); - check_in_window (win); - } + WinData *win; + + win = new_windata(); + if (!(body->add_config_data.windows_flags & TRANSIENT)) { + win->app_id = body->add_config_data.app_id; + win->app_id_set = 1; + set_win_configuration(win, body); + + insert_win_hashtab(win); + check_win_complete(win); + check_in_window(win); + } } -static void destroy_window (FvwmPacketBody *body) +static void +destroy_window(FvwmPacketBody *body) { - WinData *win; - Ulong app_id; - - app_id = body->minimal_data.app_id; - win = id_to_win (app_id); - if (win == globals.focus_win) - globals.focus_win = NULL; - delete_win_hashtab (win); - if (win->button) { - ConsoleDebug (FVWM, "destroy_window: deleting windows_button\n"); - delete_windows_button (win); - } - free_windata (win); + WinData *win; + Ulong app_id; + + app_id = body->minimal_data.app_id; + win = id_to_win(app_id); + if (win == globals.focus_win) + globals.focus_win = NULL; + delete_win_hashtab(win); + if (win->button) { + ConsoleDebug(FVWM, "destroy_window: deleting windows_button\n"); + delete_windows_button(win); + } + free_windata(win); } #ifdef MINI_ICONS -static void mini_icon (FvwmPacketBody *body) +static void +mini_icon(FvwmPacketBody *body) { - Ulong app_id = body->mini_icon_data.app_id; - WinData *win; - - win = id_to_win (app_id); - set_win_picture (win, body->mini_icon_data.picture, - body->mini_icon_data.mask, body->mini_icon_data.depth, - body->mini_icon_data.width, body->mini_icon_data.height); + Ulong app_id = body->mini_icon_data.app_id; + WinData *win; + win = id_to_win(app_id); + set_win_picture(win, body->mini_icon_data.picture, + body->mini_icon_data.mask, body->mini_icon_data.depth, + body->mini_icon_data.width, body->mini_icon_data.height); - ConsoleDebug (FVWM, "mini_icon: 0x%lx 0x%lx %dx%dx%d\n", - (unsigned long) win->pic.picture, - (unsigned long) win->pic.mask, - win->pic.width, win->pic.height, win->pic.depth); + ConsoleDebug(FVWM, "mini_icon: 0x%lx 0x%lx %dx%dx%d\n", + (unsigned long)win->pic.picture, (unsigned long)win->pic.mask, + win->pic.width, win->pic.height, win->pic.depth); } #endif -static void iconify (FvwmPacketBody *body, int dir) +static void +iconify(FvwmPacketBody *body, int dir) { - Ulong app_id = body->minimal_data.app_id; - WinData *win; + Ulong app_id = body->minimal_data.app_id; + WinData *win; - win = id_to_win (app_id); + win = id_to_win(app_id); - set_win_iconified (win, dir); + set_win_iconified(win, dir); - check_win_complete (win); - check_in_window (win); + check_win_complete(win); + check_in_window(win); } /* only used by new_desk */ -static void update_win_in_hashtab (void *arg) +static void +update_win_in_hashtab(void *arg) { - WinData *p = (WinData *)arg; - check_in_window (p); + WinData *p = (WinData *)arg; + check_in_window(p); } -static void new_desk (FvwmPacketBody *body) +static void +new_desk(FvwmPacketBody *body) { - globals.desknum = body->new_desk_data.desknum; - walk_hashtab (update_win_in_hashtab); + globals.desknum = body->new_desk_data.desknum; + walk_hashtab(update_win_in_hashtab); - draw_managers (); + draw_managers(); } -static void sendtomodule (FvwmPacketBody *body) +static void +sendtomodule(FvwmPacketBody *body) { - extern void execute_function (char *); - Uchar *string = body->name_data.name.name; + extern void execute_function(char *); + Uchar *string = body->name_data.name.name; - ConsoleDebug (FVWM, "Got string: %s\n", string); + ConsoleDebug(FVWM, "Got string: %s\n", string); - execute_function (string); + execute_function(string); } -static void ProcessMessage (Ulong type, FvwmPacketBody *body) +static void +ProcessMessage(Ulong type, FvwmPacketBody *body) { - int i; + int i; - ConsoleDebug (FVWM, "FVWM Message type: %ld\n", type); + ConsoleDebug(FVWM, "FVWM Message type: %ld\n", type); - switch(type) { - case M_CONFIGURE_WINDOW: - ConsoleDebug (FVWM, "DEBUG::M_CONFIGURE_WINDOW\n"); - configure_window (body); - break; + switch (type) { + case M_CONFIGURE_WINDOW: + ConsoleDebug(FVWM, "DEBUG::M_CONFIGURE_WINDOW\n"); + configure_window(body); + break; - case M_FOCUS_CHANGE: - ConsoleDebug (FVWM, "DEBUG::M_FOCUS_CHANGE\n"); - focus_change (body); - break; + case M_FOCUS_CHANGE: + ConsoleDebug(FVWM, "DEBUG::M_FOCUS_CHANGE\n"); + focus_change(body); + break; - case M_RES_NAME: - ConsoleDebug (FVWM, "DEBUG::M_RES_NAME\n"); - res_name (body); - break; + case M_RES_NAME: + ConsoleDebug(FVWM, "DEBUG::M_RES_NAME\n"); + res_name(body); + break; - case M_RES_CLASS: - ConsoleDebug (FVWM, "DEBUG::M_RES_CLASS\n"); - class_name (body); - break; + case M_RES_CLASS: + ConsoleDebug(FVWM, "DEBUG::M_RES_CLASS\n"); + class_name(body); + break; - case M_MAP: - ConsoleDebug (FVWM, "DEBUG::M_MAP\n"); - break; + case M_MAP: + ConsoleDebug(FVWM, "DEBUG::M_MAP\n"); + break; - case M_ADD_WINDOW: - ConsoleDebug (FVWM, "DEBUG::M_ADD_WINDOW\n"); - new_window (body); - break; + case M_ADD_WINDOW: + ConsoleDebug(FVWM, "DEBUG::M_ADD_WINDOW\n"); + new_window(body); + break; - case M_DESTROY_WINDOW: - ConsoleDebug (FVWM, "DEBUG::M_DESTROY_WINDOW\n"); - destroy_window (body); - break; + case M_DESTROY_WINDOW: + ConsoleDebug(FVWM, "DEBUG::M_DESTROY_WINDOW\n"); + destroy_window(body); + break; #ifdef MINI_ICONS - case M_MINI_ICON: - ConsoleDebug (FVWM, "DEBUG::M_MINI_ICON\n"); - mini_icon (body); - break; + case M_MINI_ICON: + ConsoleDebug(FVWM, "DEBUG::M_MINI_ICON\n"); + mini_icon(body); + break; #endif - case M_WINDOW_NAME: - ConsoleDebug (FVWM, "DEBUG::M_WINDOW_NAME\n"); - window_name (body); - break; - - case M_ICON_NAME: - ConsoleDebug (FVWM, "DEBUG::M_ICON_NAME\n"); - icon_name (body); - break; - - case M_DEICONIFY: - ConsoleDebug (FVWM, "DEBUG::M_DEICONIFY\n"); - iconify (body, 0); - break; - - case M_ICONIFY: - ConsoleDebug (FVWM, "DEBUG::M_ICONIFY\n"); - iconify (body, 1); - break; - - case M_END_WINDOWLIST: - ConsoleDebug (FVWM, "DEBUG::M_END_WINDOWLIST\n"); - ConsoleDebug (FVWM, - ">>>>>>>>>>>>>>>>>>>>>>>End window list<<<<<<<<<<<<<<<\n"); - if (globals.focus_win && globals.focus_win->button) { - globals.focus_win->manager->focus_button = globals.focus_win->button; - } - globals.got_window_list = 1; - for (i = 0; i < globals.num_managers; i++) { - create_manager_window (i); - } - break; - - case M_NEW_DESK: - ConsoleDebug (FVWM, "DEBUG::M_NEW_DESK\n"); - new_desk (body); - break; - - case M_NEW_PAGE: - ConsoleDebug (FVWM, "DEBUG::M_NEW_PAGE\n"); - if (globals.x == body->new_page_data.x && - globals.y == body->new_page_data.y && - globals.desknum == body->new_page_data.desknum) { - ConsoleDebug (FVWM, "Useless NEW_PAGE received\n"); - break; - } - globals.x = body->new_page_data.x; - globals.y = body->new_page_data.y; - globals.desknum = body->new_page_data.desknum; - for (i = 0; i < globals.num_managers; i++) { - set_draw_mode (&globals.managers[i], 0); - } - break; - - case M_STRING: - ConsoleDebug (FVWM, "DEBUG::M_STRING\n"); - sendtomodule (body); - break; - - default: - break; - } - - check_managers_consistency(); - - for (i = 0; i < globals.num_managers; i++) { - if (drawing (&globals.managers[i])) - draw_manager (&globals.managers[i]); - } - - check_managers_consistency(); + case M_WINDOW_NAME: + ConsoleDebug(FVWM, "DEBUG::M_WINDOW_NAME\n"); + window_name(body); + break; + + case M_ICON_NAME: + ConsoleDebug(FVWM, "DEBUG::M_ICON_NAME\n"); + icon_name(body); + break; + + case M_DEICONIFY: + ConsoleDebug(FVWM, "DEBUG::M_DEICONIFY\n"); + iconify(body, 0); + break; + + case M_ICONIFY: + ConsoleDebug(FVWM, "DEBUG::M_ICONIFY\n"); + iconify(body, 1); + break; + + case M_END_WINDOWLIST: + ConsoleDebug(FVWM, "DEBUG::M_END_WINDOWLIST\n"); + ConsoleDebug(FVWM, + ">>>>>>>>>>>>>>>>>>>>>>>End window list<<<<<<<<<<<<<<<\n"); + if (globals.focus_win && globals.focus_win->button) { + globals.focus_win->manager->focus_button = + globals.focus_win->button; + } + globals.got_window_list = 1; + for (i = 0; i < globals.num_managers; i++) { + create_manager_window(i); + } + break; + + case M_NEW_DESK: + ConsoleDebug(FVWM, "DEBUG::M_NEW_DESK\n"); + new_desk(body); + break; + + case M_NEW_PAGE: + ConsoleDebug(FVWM, "DEBUG::M_NEW_PAGE\n"); + if (globals.x == body->new_page_data.x && + globals.y == body->new_page_data.y && + globals.desknum == body->new_page_data.desknum) { + ConsoleDebug(FVWM, "Useless NEW_PAGE received\n"); + break; + } + globals.x = body->new_page_data.x; + globals.y = body->new_page_data.y; + globals.desknum = body->new_page_data.desknum; + for (i = 0; i < globals.num_managers; i++) { + set_draw_mode(&globals.managers[i], 0); + } + break; + + case M_STRING: + ConsoleDebug(FVWM, "DEBUG::M_STRING\n"); + sendtomodule(body); + break; + + default: + break; + } + + check_managers_consistency(); + + for (i = 0; i < globals.num_managers; i++) { + if (drawing(&globals.managers[i])) + draw_manager(&globals.managers[i]); + } + + check_managers_consistency(); } -void ReadFvwmPipe (void) +void +ReadFvwmPipe(void) { - int body_length; - FvwmPacketHeader header; - FvwmPacketBody *body; - - PrintMemuse(); - - ConsoleDebug(FVWM, "DEBUG: entering ReadFvwmPipe\n"); - body_length = ReadFvwmPacket(Fvwm_fd[1], (unsigned long *) &header, - (unsigned long **)&body); - body_length -= HEADER_SIZE; - if (header.start == START_FLAG) { - ProcessMessage (header.type, body); - if (body_length) { - Free (body); - } - } - else { - DeadPipe (1); - } - ConsoleDebug(FVWM, "DEBUG: leaving ReadFvwmPipe\n"); + int body_length; + FvwmPacketHeader header; + FvwmPacketBody *body; + + PrintMemuse(); + + ConsoleDebug(FVWM, "DEBUG: entering ReadFvwmPipe\n"); + body_length = ReadFvwmPacket( + Fvwm_fd[1], (unsigned long *)&header, (unsigned long **)&body); + body_length -= HEADER_SIZE; + if (header.start == START_FLAG) { + ProcessMessage(header.type, body); + if (body_length) { + Free(body); + } + } else { + DeadPipe(1); + } + ConsoleDebug(FVWM, "DEBUG: leaving ReadFvwmPipe\n"); } Index: fvwm/modules/FvwmIconMan/globals.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/globals.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/globals.c --- fvwm/modules/FvwmIconMan/globals.c +++ fvwm/modules/FvwmIconMan/globals.c @@ -1,155 +1,151 @@ #include + #include "FvwmIconMan.h" -#include "xmanager.h" #include "readconfig.h" +#include "xmanager.h" #define DEFAULT_MOUSE "0 N sendcommand Iconify" static char const rcsid[] = - "$Id: globals.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; + "$Id: globals.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; GlobalData globals; ContextDefaults contextDefaults[] = { - { "plain", BUTTON_UP, { "black", "black" }, { "white", "gray"} }, - { "focus", BUTTON_UP, { "white", "gray" }, { "black", "black" } }, - { "select", BUTTON_FLAT, { "black", "black" }, { "white", "gray" } }, - { "focusandselect", BUTTON_FLAT, { "white", "gray" }, { "black", "black" } }, - { "title", BUTTON_EDGEUP, { "black", "black"}, {"white", "gray"} } -}; + {"plain", BUTTON_UP, {"black", "black"}, {"white", "gray"}}, + {"focus", BUTTON_UP, {"white", "gray"}, {"black", "black"}}, + {"select", BUTTON_FLAT, {"black", "black"}, {"white", "gray"}}, + {"focusandselect", BUTTON_FLAT, {"white", "gray"}, {"black", "black"}}, + {"title", BUTTON_EDGEUP, {"black", "black"}, {"white", "gray"}}}; int Fvwm_fd[2]; int x_fd; char *Module = "*FvwmIconMan"; int ModuleLen = 12; -/* This is solely so that we can turn a string constant into something - which can be freed */ - -static char *alloc_string (char *string) +static void +init_win_manager(int id) { - int len = strlen (string); - char *ret = (char *)safemalloc ((len + 1) * sizeof (char)); - strcpy (ret, string); - return ret; -} - -static void init_win_manager (int id) -{ - int i; + int i; - globals.managers[id].magic = 0x12344321; - globals.managers[id].index = id; + globals.managers[id].magic = 0x12344321; + globals.managers[id].index = id; #ifdef MINI_ICONS - globals.managers[id].draw_icons = 0; + globals.managers[id].draw_icons = 0; #endif - globals.managers[id].res = SHOW_PAGE; - globals.managers[id].window_up = 0; - globals.managers[id].can_draw = 0; - globals.managers[id].window_mapped = 0; - globals.managers[id].fontname = NULL; - globals.managers[id].titlename = alloc_string ("FvwmIconMan"); - globals.managers[id].iconname = alloc_string ("FvwmIconMan"); - globals.managers[id].formatstring = alloc_string ("%c: %i"); - globals.managers[id].format_depend = CLASS_NAME | ICON_NAME; - globals.managers[id].geometry.dir = 0; - globals.managers[id].geometry.boxwidth = 0; + globals.managers[id].res = SHOW_PAGE; + globals.managers[id].window_up = 0; + globals.managers[id].can_draw = 0; + globals.managers[id].window_mapped = 0; + globals.managers[id].fontname = NULL; + globals.managers[id].titlename = xstrdup("FvwmIconMan"); + globals.managers[id].iconname = xstrdup("FvwmIconMan"); + globals.managers[id].formatstring = xstrdup("%c: %i"); + globals.managers[id].format_depend = CLASS_NAME | ICON_NAME; + globals.managers[id].geometry.dir = 0; + globals.managers[id].geometry.boxwidth = 0; #ifdef SHAPE - globals.managers[id].shape.num_rects = 0; + globals.managers[id].shape.num_rects = 0; #endif - globals.managers[id].shaped = 0; - init_button_array (&globals.managers[id].buttons); - - for ( i = 0; i < NUM_CONTEXTS; i++ ) { - globals.managers[id].backColorName[i] = NULL; - globals.managers[id].foreColorName[i] = NULL; - globals.managers[id].buttonState[i] = contextDefaults[i].state; - } - globals.managers[id].geometry_str = NULL; - globals.managers[id].button_geometry_str = NULL; - globals.managers[id].show.list = NULL; - globals.managers[id].show.mask = ALL_NAME; - globals.managers[id].dontshow.list = NULL; - globals.managers[id].dontshow.mask = ALL_NAME; - globals.managers[id].followFocus = 0; - globals.managers[id].usewinlist = 1; - globals.managers[id].sort = SortName; - globals.managers[id].focus_button = NULL; - globals.managers[id].select_button = NULL; - globals.managers[id].bindings[MOUSE] = ParseMouseEntry (DEFAULT_MOUSE); - globals.managers[id].bindings[KEYPRESS] = NULL; - globals.managers[id].bindings[SELECT] = NULL; - globals.managers[id].we_are_drawing = 1; - globals.managers[id].configures_expected = 0; + globals.managers[id].shaped = 0; + init_button_array(&globals.managers[id].buttons); + + for (i = 0; i < NUM_CONTEXTS; i++) { + globals.managers[id].backColorName[i] = NULL; + globals.managers[id].foreColorName[i] = NULL; + globals.managers[id].buttonState[i] = contextDefaults[i].state; + } + globals.managers[id].geometry_str = NULL; + globals.managers[id].button_geometry_str = NULL; + globals.managers[id].show.list = NULL; + globals.managers[id].show.mask = ALL_NAME; + globals.managers[id].dontshow.list = NULL; + globals.managers[id].dontshow.mask = ALL_NAME; + globals.managers[id].followFocus = 0; + globals.managers[id].usewinlist = 1; + globals.managers[id].sort = SortName; + globals.managers[id].focus_button = NULL; + globals.managers[id].select_button = NULL; + globals.managers[id].bindings[MOUSE] = ParseMouseEntry(DEFAULT_MOUSE); + globals.managers[id].bindings[KEYPRESS] = NULL; + globals.managers[id].bindings[SELECT] = NULL; + globals.managers[id].we_are_drawing = 1; + globals.managers[id].configures_expected = 0; } -void print_managers (void) +void +print_managers(void) { #ifdef PRINT_DEBUG - int i; - - for (i = 0; i < globals.num_managers; i++) { - ConsoleDebug (CORE, "Manager %d:\n", i + 1); - if (globals.managers[i].res == SHOW_GLOBAL) - ConsoleDebug (CORE, "ShowGlobal\n"); - else if (globals.managers[i].res == SHOW_DESKTOP) - ConsoleDebug (CORE, "ShowDesktop\n"); - else if (globals.managers[i].res == SHOW_PAGE) - ConsoleDebug (CORE, "ShowPage\n"); - - ConsoleDebug (CORE, "DontShow:\n"); - print_stringlist (&globals.managers[i].dontshow); - ConsoleDebug (CORE, "Show:\n"); - print_stringlist (&globals.managers[i].show); - - ConsoleDebug (CORE, "Font: %s\n", (globals.managers[i].fontname)? - globals.managers[i].fontname : "(NULL)"); - ConsoleDebug (CORE, "Geometry: %s\n", globals.managers[i].geometry_str); - ConsoleDebug (CORE, "Button geometry: %s\n", - (globals.managers[i].button_geometry_str)? - globals.managers[i].button_geometry_str : "(NULL)"); - ConsoleDebug (CORE, "\n"); - } + int i; + + for (i = 0; i < globals.num_managers; i++) { + ConsoleDebug(CORE, "Manager %d:\n", i + 1); + if (globals.managers[i].res == SHOW_GLOBAL) + ConsoleDebug(CORE, "ShowGlobal\n"); + else if (globals.managers[i].res == SHOW_DESKTOP) + ConsoleDebug(CORE, "ShowDesktop\n"); + else if (globals.managers[i].res == SHOW_PAGE) + ConsoleDebug(CORE, "ShowPage\n"); + + ConsoleDebug(CORE, "DontShow:\n"); + print_stringlist(&globals.managers[i].dontshow); + ConsoleDebug(CORE, "Show:\n"); + print_stringlist(&globals.managers[i].show); + + ConsoleDebug(CORE, "Font: %s\n", + (globals.managers[i].fontname) ? + globals.managers[i].fontname : + "(NULL)"); + ConsoleDebug( + CORE, "Geometry: %s\n", globals.managers[i].geometry_str); + ConsoleDebug(CORE, "Button geometry: %s\n", + (globals.managers[i].button_geometry_str) ? + globals.managers[i].button_geometry_str : + "(NULL)"); + ConsoleDebug(CORE, "\n"); + } #endif - } -int allocate_managers (int num) +int +allocate_managers(int num) { - int i; + int i; - if (globals.managers) { - ConsoleMessage ("Already have set the number of managers\n"); - return 0; - } + if (globals.managers) { + ConsoleMessage("Already have set the number of managers\n"); + return 0; + } - if (num < 1) { - ConsoleMessage ("Can't have %d managers\n", num); - return 0; - } + if (num < 1) { + ConsoleMessage("Can't have %d managers\n", num); + return 0; + } - globals.num_managers = num; - globals.managers = (WinManager *)safemalloc (num * sizeof (WinManager)); + globals.num_managers = num; + globals.managers = (WinManager *)xmalloc(num * sizeof(WinManager)); - for (i = 0; i < num; i++) { - init_win_manager (i); - } + for (i = 0; i < num; i++) { + init_win_manager(i); + } - return 1; + return 1; } -void init_globals (void) +void +init_globals(void) { - globals.desknum = ULONG_MAX; - globals.x = ULONG_MAX; - globals.y = ULONG_MAX; - globals.screenx = 0; - globals.screeny = 0; - globals.num_managers = 1; - globals.managers = NULL; - globals.focus_win = NULL; - globals.select_win = NULL; - globals.transient = 0; - globals.shapes_supported = 0; - globals.got_window_list = 0; + globals.desknum = ULONG_MAX; + globals.x = ULONG_MAX; + globals.y = ULONG_MAX; + globals.screenx = 0; + globals.screeny = 0; + globals.num_managers = 1; + globals.managers = NULL; + globals.focus_win = NULL; + globals.select_win = NULL; + globals.transient = 0; + globals.shapes_supported = 0; + globals.got_window_list = 0; } Index: fvwm/modules/FvwmIconMan/readconfig.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/readconfig.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/readconfig.c --- fvwm/modules/FvwmIconMan/readconfig.c +++ fvwm/modules/FvwmIconMan/readconfig.c @@ -1,10 +1,12 @@ +#include "readconfig.h" + #include #include + #include "FvwmIconMan.h" -#include "readconfig.h" static char const rcsid[] = - "$Id: readconfig.c,v 1.1.1.1 2006/11/26 10:53:50 matthieu Exp $"; + "$Id: readconfig.c,v 1.1.1.1 2006/11/26 10:53:50 matthieu Exp $"; /************************************************************************ * @@ -12,262 +14,251 @@ static char const rcsid[] = * ************************************************************************/ -extern int builtin_quit (int numargs, BuiltinArg *args); -extern int builtin_printdebug (int numargs, BuiltinArg *args); -extern int builtin_gotobutton (int numargs, BuiltinArg *args); -extern int builtin_gotomanager (int numargs, BuiltinArg *args); -extern int builtin_refresh (int numargs, BuiltinArg *args); -extern int builtin_select (int numargs, BuiltinArg *args); -extern int builtin_sendcommand (int numargs, BuiltinArg *args); -extern int builtin_bif (int numargs, BuiltinArg *args); -extern int builtin_bifn (int numargs, BuiltinArg *args); -extern int builtin_print (int numargs, BuiltinArg *args); -extern int builtin_jmp (int numargs, BuiltinArg *args); -extern int builtin_ret (int numargs, BuiltinArg *args); -extern int builtin_searchforward (int numargs, BuiltinArg *args); -extern int builtin_searchback (int numargs, BuiltinArg *args); -extern int builtin_warp (int numargs, BuiltinArg *args); +extern int builtin_quit(int numargs, BuiltinArg *args); +extern int builtin_printdebug(int numargs, BuiltinArg *args); +extern int builtin_gotobutton(int numargs, BuiltinArg *args); +extern int builtin_gotomanager(int numargs, BuiltinArg *args); +extern int builtin_refresh(int numargs, BuiltinArg *args); +extern int builtin_select(int numargs, BuiltinArg *args); +extern int builtin_sendcommand(int numargs, BuiltinArg *args); +extern int builtin_bif(int numargs, BuiltinArg *args); +extern int builtin_bifn(int numargs, BuiltinArg *args); +extern int builtin_print(int numargs, BuiltinArg *args); +extern int builtin_jmp(int numargs, BuiltinArg *args); +extern int builtin_ret(int numargs, BuiltinArg *args); +extern int builtin_searchforward(int numargs, BuiltinArg *args); +extern int builtin_searchback(int numargs, BuiltinArg *args); +extern int builtin_warp(int numargs, BuiltinArg *args); /* compiler pseudo-functions */ -static int builtin_label (int numargs, BuiltinArg *args); +static int builtin_label(int numargs, BuiltinArg *args); typedef struct { - char *name; - int (*func)(int numargs, BuiltinArg *args); - int numargs; - BuiltinArgType args[MAX_ARGS]; + char *name; + int (*func)(int numargs, BuiltinArg *args); + int numargs; + BuiltinArgType args[MAX_ARGS]; } FunctionType; /* * these are now sorted so we can use bsearch on them. */ FunctionType builtin_functions[] = { - { "bif", builtin_bif, 2, { ButtonArg, JmpArg } }, - { "bifn", builtin_bifn, 2, { ButtonArg, JmpArg } }, - { "gotobutton", builtin_gotobutton, 1, { ButtonArg } }, - { "gotomanager", builtin_gotomanager, 1, { ManagerArg } }, - { "jmp", builtin_jmp, 1, { JmpArg } }, - { "label", builtin_label, 1, { StringArg } }, - { "print", builtin_print, 1, { StringArg } }, - { "printdebug", builtin_printdebug, 0 }, - { "quit", builtin_quit, 0 }, - { "refresh", builtin_refresh, 0 }, - { "ret", builtin_ret, 0 }, - { "searchback", builtin_searchback, 1, { StringArg } }, - { "searchforward", builtin_searchforward, 1, { StringArg } }, - { "select", builtin_select, 0 }, - { "sendcommand", builtin_sendcommand, 1, { StringArg } }, - { "warp", builtin_warp, 0 } -}; - -static int num_builtins = sizeof (builtin_functions) / sizeof (FunctionType); + {"bif", builtin_bif, 2, {ButtonArg, JmpArg}}, + {"bifn", builtin_bifn, 2, {ButtonArg, JmpArg}}, + {"gotobutton", builtin_gotobutton, 1, {ButtonArg}}, + {"gotomanager", builtin_gotomanager, 1, {ManagerArg}}, + {"jmp", builtin_jmp, 1, {JmpArg}}, {"label", builtin_label, 1, {StringArg}}, + {"print", builtin_print, 1, {StringArg}}, + {"printdebug", builtin_printdebug, 0}, {"quit", builtin_quit, 0}, + {"refresh", builtin_refresh, 0}, {"ret", builtin_ret, 0}, + {"searchback", builtin_searchback, 1, {StringArg}}, + {"searchforward", builtin_searchforward, 1, {StringArg}}, + {"select", builtin_select, 0}, + {"sendcommand", builtin_sendcommand, 1, {StringArg}}, + {"warp", builtin_warp, 0}}; + +static int num_builtins = sizeof(builtin_functions) / sizeof(FunctionType); /************************************************************************/ - -struct charstring -{ - char key; - int value; +struct charstring { + char key; + int value; }; -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} -}; +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}}; #if FVWM_VERSION == 1 static FILE *config_fp = NULL; #endif - /* This is only used for printing out the .fvwmrc line if an error occured */ #define PRINT_LINE_LENGTH 80 static char current_line[PRINT_LINE_LENGTH]; -static void save_current_line (char *s) +static void +save_current_line(char *s) { - char *p = current_line; - - while (*s && p < current_line + PRINT_LINE_LENGTH - 1) { - if (*s == '\n') { - *p = '\0'; - return; - } - else { - *p++ = *s++; - } - } - *p = '\0'; + char *p = current_line; + + while (*s && p < current_line + PRINT_LINE_LENGTH - 1) { + if (*s == '\n') { + *p = '\0'; + return; + } else { + *p++ = *s++; + } + } + *p = '\0'; } -void print_args (int numargs, BuiltinArg *args) +void +print_args(int numargs, BuiltinArg *args) { #ifdef PRINT_DEBUG - int i; - - for (i = 0; i < numargs; i++) { - switch (args[i].type) { - case NoArg: - ConsoleDebug (CONFIG, "NoArg "); - break; - - case IntArg: - ConsoleDebug (CONFIG, "Int: %d ", args[i].value.int_value); - break; - - case StringArg: - ConsoleDebug (CONFIG, "String: %s ", args[i].value.string_value); - break; - - case ButtonArg: - ConsoleDebug (CONFIG, "Button: %d %d ", - args[i].value.button_value.offset, - args[i].value.button_value.base); - break; - - case WindowArg: - ConsoleDebug (CONFIG, "Window: %d %d ", - args[i].value.button_value.offset, - args[i].value.button_value.base); - break; - - case ManagerArg: - ConsoleDebug (CONFIG, "Manager: %d %d ", - args[i].value.button_value.offset, - args[i].value.button_value.base); - break; - - case JmpArg: - ConsoleDebug (CONFIG, "Unprocessed Label Jump: %s ", - args[i].value.string_value); - break; - - default: - ConsoleDebug (CONFIG, "bad "); - break; - } - } - ConsoleDebug (CONFIG, "\n"); + int i; + + for (i = 0; i < numargs; i++) { + switch (args[i].type) { + case NoArg: + ConsoleDebug(CONFIG, "NoArg "); + break; + + case IntArg: + ConsoleDebug( + CONFIG, "Int: %d ", args[i].value.int_value); + break; + + case StringArg: + ConsoleDebug( + CONFIG, "String: %s ", args[i].value.string_value); + break; + + case ButtonArg: + ConsoleDebug(CONFIG, "Button: %d %d ", + args[i].value.button_value.offset, + args[i].value.button_value.base); + break; + + case WindowArg: + ConsoleDebug(CONFIG, "Window: %d %d ", + args[i].value.button_value.offset, + args[i].value.button_value.base); + break; + + case ManagerArg: + ConsoleDebug(CONFIG, "Manager: %d %d ", + args[i].value.button_value.offset, + args[i].value.button_value.base); + break; + + case JmpArg: + ConsoleDebug(CONFIG, "Unprocessed Label Jump: %s ", + args[i].value.string_value); + break; + + default: + ConsoleDebug(CONFIG, "bad "); + break; + } + } + ConsoleDebug(CONFIG, "\n"); #endif } #ifdef PRINT_DEBUG -static void print_binding (Binding *binding) +static void +print_binding(Binding *binding) { - int i; - Function *func; - - if (binding->IsMouse) { - ConsoleDebug (CONFIG, "\tMouse: %d\n", binding->Button_Key); - } - else { - ConsoleDebug (CONFIG, "\tKey or action: %d %s\n", binding->Button_Key, - binding->key_name); - } - - ConsoleDebug (CONFIG, "\tModifiers: %d\n", binding->Modifier); - ConsoleDebug (CONFIG, "\tAction: %s\n", binding->Action); - ConsoleDebug (CONFIG, "\tFunction struct: %p\n", binding->Function); - func = binding->Function; - while (func) { - for (i = 0; i < num_builtins; i++) { - if (func->func == builtin_functions[i].func) { - ConsoleDebug (CONFIG, "\tFunction: %s %p ", - builtin_functions[i].name, func->func); - break; - } - } - if (i > num_builtins) { - ConsoleDebug (CONFIG, "\tFunction: not found %p ", func->func); - } - print_args (func->numargs, func->args); - func = func->next; - } + int i; + Function *func; + + if (binding->IsMouse) { + ConsoleDebug(CONFIG, "\tMouse: %d\n", binding->Button_Key); + } else { + ConsoleDebug(CONFIG, "\tKey or action: %d %s\n", + binding->Button_Key, binding->key_name); + } + + ConsoleDebug(CONFIG, "\tModifiers: %d\n", binding->Modifier); + ConsoleDebug(CONFIG, "\tAction: %s\n", binding->Action); + ConsoleDebug(CONFIG, "\tFunction struct: %p\n", binding->Function); + func = binding->Function; + while (func) { + for (i = 0; i < num_builtins; i++) { + if (func->func == builtin_functions[i].func) { + ConsoleDebug(CONFIG, "\tFunction: %s %p ", + builtin_functions[i].name, func->func); + break; + } + } + if (i > num_builtins) { + ConsoleDebug( + CONFIG, "\tFunction: not found %p ", func->func); + } + print_args(func->numargs, func->args); + func = func->next; + } } -#endif +#endif -void print_bindings (Binding *list) +void +print_bindings(Binding *list) { #ifdef PRINT_DEBUG - ConsoleDebug (CONFIG, "binding list:\n"); - while (list != NULL) { - print_binding (list); - ConsoleDebug (CONFIG, "\n"); - list = list->NextBinding; - } + ConsoleDebug(CONFIG, "binding list:\n"); + while (list != NULL) { + print_binding(list); + ConsoleDebug(CONFIG, "\n"); + list = list->NextBinding; + } #endif } -static int iswhite (char c) +static int +iswhite(char c) { - if (c == ' ' || c == '\t' || c == '\0') - return 1; - return 0; + if (c == ' ' || c == '\t' || c == '\0') + return 1; + return 0; } -static void skip_space (char **p) +static void +skip_space(char **p) { - while (**p == ' ' || **p == '\t') - (*p)++; + while (**p == ' ' || **p == '\t') + (*p)++; } -static void add_to_binding (Binding **list, Binding *binding) +static void +add_to_binding(Binding **list, Binding *binding) { - ConsoleDebug (CONFIG, "In add_to_binding:\n"); - - if (*list == NULL) { - *list = binding; - } - else { - binding->LastBinding->NextBinding = *list; - *list = binding; - } + ConsoleDebug(CONFIG, "In add_to_binding:\n"); + + if (*list == NULL) { + *list = binding; + } else { + binding->LastBinding->NextBinding = *list; + *list = binding; + } } -static int extract_int (char *p, int *n) +static int +extract_int(char *p, int *n) { - char *s; - int sign = 1; - - while (isspace (*p) && *p) - p++; - - if (*p == '-') { - sign = -1; - p++; - } - else if (*p == '+') { - sign = 1; - p++; - } - - if (*p == '\0') { - return 0; - } - - for (s = p; *s; s++) { - if (*s < '0' || *s > '9') { - return 0; - } - } - - *n = atoi (p) * sign; - - return 1; -} + char *s; + int sign = 1; + + while (isspace(*p) && *p) + p++; + + if (*p == '-') { + sign = -1; + p++; + } else if (*p == '+') { + sign = 1; + p++; + } + + if (*p == '\0') { + return 0; + } + + for (s = p; *s; s++) { + if (*s < '0' || *s > '9') { + return 0; + } + } + + *n = atoi(p) * sign; + + return 1; +} /**************************************************************************** * @@ -275,1315 +266,1449 @@ static int extract_int (char *p, int *n) * "word" is a string with no spaces, or a qouted string. * 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. + * The token is the extracted word, which is copied into a malloced + * space, and must be freed after use. * **************************************************************************/ -static void find_context(char *string, int *output, struct charstring *table, - char *tline) +static 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(itype = ButtonArg; - bv = &arg->value.button_value; - bv->offset = 0; - bv->base = AbsoluteButton; - - rest = DoGetNextToken (string, &token, NULL, ",", pstop_char); - if (token == NULL) { - bv->base = NoButton; - *flag = 0; - Free(token); - return NULL; - } - if (!strcasecmp (token, "focus")) { - bv->base = FocusButton; - } - else if (!strcasecmp (token, "select")) { - bv->base = SelectButton; - } - else if (!strcasecmp (token, "up")) { - bv->base = UpButton; - } - else if (!strcasecmp (token, "down")) { - bv->base = DownButton; - } - else if (!strcasecmp (token, "left")) { - bv->base = LeftButton; - } - else if (!strcasecmp (token, "right")) { - bv->base = RightButton; - } - else if (!strcasecmp (token, "next")) { - bv->base = NextButton; - } - else if (!strcasecmp (token, "prev")) { - bv->base = PrevButton; - } - else if (extract_int (token, &n)) { - bv->base = AbsoluteButton; - bv->offset = n; - } - else { - ConsoleMessage ("Bad button: %s\n", token); - bv->base = NoButton; - Free (token); - *flag = 0; - return NULL; - } - - Free (token); - return rest; + char *rest, *token; + ButtonValue *bv; + int n; + + ConsoleDebug(CONFIG, "parse_term: %s\n", string); + + *flag = 1; + + arg->type = ButtonArg; + bv = &arg->value.button_value; + bv->offset = 0; + bv->base = AbsoluteButton; + + rest = DoGetNextToken(string, &token, NULL, ",", pstop_char); + if (token == NULL) { + bv->base = NoButton; + *flag = 0; + Free(token); + return NULL; + } + if (!strcasecmp(token, "focus")) { + bv->base = FocusButton; + } else if (!strcasecmp(token, "select")) { + bv->base = SelectButton; + } else if (!strcasecmp(token, "up")) { + bv->base = UpButton; + } else if (!strcasecmp(token, "down")) { + bv->base = DownButton; + } else if (!strcasecmp(token, "left")) { + bv->base = LeftButton; + } else if (!strcasecmp(token, "right")) { + bv->base = RightButton; + } else if (!strcasecmp(token, "next")) { + bv->base = NextButton; + } else if (!strcasecmp(token, "prev")) { + bv->base = PrevButton; + } else if (extract_int(token, &n)) { + bv->base = AbsoluteButton; + bv->offset = n; + } else { + ConsoleMessage("Bad button: %s\n", token); + bv->base = NoButton; + Free(token); + *flag = 0; + return NULL; + } + + Free(token); + return rest; } -static void free_function_list (Function *func) +static void +free_function_list(Function *func) { - int i; - Function *fp = func; - - while (fp) { - for (i = 0; i < fp->numargs; i++) { - if (fp->args[i].type == StringArg) - Free (fp->args[i].value.string_value); - } - func = fp; - fp = fp->next; - Free (func); - } + int i; + Function *fp = func; + + while (fp) { + for (i = 0; i < fp->numargs; i++) { + if (fp->args[i].type == StringArg) + Free(fp->args[i].value.string_value); + } + func = fp; + fp = fp->next; + Free(func); + } } - -static int funccasecmp(const void *key /* actually char* */, - const void *member /* actually FunctionType* */) + +static int +funccasecmp(const void *key /* actually char* */, + const void *member /* actually FunctionType* */) { - return strcasecmp((char *)key, ((FunctionType *)member)->name); + return strcasecmp((char *)key, ((FunctionType *)member)->name); } /* * The label function. Should never be called, but we need a pointer to it, * and it's useful for debugging purposes to have it defined. */ -static int builtin_label (int numargs, BuiltinArg *args) { - int j; - /* we should _never_ be called */ - ConsoleMessage ( "label" ); - for (j=0; jfunc = builtin_functions_i->func; - ftype->numargs = builtin_functions_i->numargs; - ftype->next = NULL; - - for (j = 0; j < builtin_functions_i->numargs && *pstop_char != ','; j++) { - ftype->args[j].type = builtin_functions_i->args[j]; - switch (builtin_functions_i->args[j]) { - case IntArg: - ptr = DoGetNextToken (ptr, &tok, NULL, ",", pstop_char); - if (!tok) { - ConsoleMessage ("%s: too few arguments\n", - builtin_functions_i->name); - Free(ftype); - *line = NULL; - return NULL; - } - if (extract_int (tok, &ftype->args[j].value.int_value) == 0) { - ConsoleMessage ("%s: expect integer argument: %s\n", - builtin_functions_i->name, tok); - Free (tok); - Free(ftype); - *line = NULL; - return NULL; - } - Free (tok); - break; - - case StringArg: - ptr = DoGetNextToken (ptr, &ftype->args[j].value.string_value,NULL, - ",", pstop_char); - if (!ftype->args[j].value.string_value) { - ConsoleMessage ("%s: too few arguments\n", - builtin_functions_i->name); - *line = NULL; - Free(ftype->args[j].value.string_value); - Free(ftype); - return NULL; - } - ftype->args[j].type = builtin_functions_i->args[j]; - break; - - case ButtonArg: - case WindowArg: - case ManagerArg: - ptr = parse_button (ptr, &ftype->args[j], &flag, pstop_char); - if (!flag) { - ConsoleMessage ("%s: too few arguments\n", - builtin_functions_i->name); - Free(ftype); - *line = NULL; - return NULL; - } - ftype->args[j].type = builtin_functions_i->args[j]; - break; - - /* JmpArg can be a string or an int. However, if 'JmpArg' - * is recorded as the argument type in the argument array - * for a command, it means it is a string; the code for - * 'IntArg' is used instead for numbers. Note also that - * if the C function recieves a 'JmpArg' argument it means something - * went wrong, since they should all be translated to integer - * jump offsets at compile time. - */ - case JmpArg: - ptr = DoGetNextToken (ptr, &tok, NULL, ",", pstop_char); - if (!tok) { - ConsoleMessage ("%s: too few arguments\n", - builtin_functions_i->name); - Free(tok); - Free(ftype); - *line=NULL; - return NULL; - } - if (extract_int(tok, &ftype->args[j].value.int_value) == 0) { - ftype->args[j].value.string_value=tok; - ftype->args[j].type = JmpArg; - ++JmpArgs; - } else { - ftype->args[j].type = IntArg; - Free(tok); - } - break; - - default: - ConsoleMessage ("internal error in parse_function\n"); - Free(ftype); + Function *ftype = (Function *)xmalloc(sizeof(Function)); + char *ptr, *name, *tok; + int j, flag; + FunctionType *builtin_functions_i; + + ConsoleDebug(CONFIG, "in parse_function\n"); + + ptr = DoGetNextToken(*line, &name, NULL, ",", pstop_char); + if (name == NULL) { + Free(ftype); + *line = NULL; + return NULL; + } + + builtin_functions_i = bsearch((void *)name, (void *)builtin_functions, + num_builtins, sizeof(FunctionType), funccasecmp); + if (builtin_functions_i) { + Free(name); + ftype->func = builtin_functions_i->func; + ftype->numargs = builtin_functions_i->numargs; + ftype->next = NULL; + + for (j = 0; + j < builtin_functions_i->numargs && *pstop_char != ','; + j++) { + ftype->args[j].type = builtin_functions_i->args[j]; + switch (builtin_functions_i->args[j]) { + case IntArg: + ptr = DoGetNextToken( + ptr, &tok, NULL, ",", pstop_char); + if (!tok) { + ConsoleMessage( + "%s: too few arguments\n", + builtin_functions_i->name); + Free(ftype); + *line = NULL; + return NULL; + } + if (extract_int(tok, + &ftype->args[j].value.int_value) == 0) { + ConsoleMessage( + "%s: expect integer argument: %s\n", + builtin_functions_i->name, tok); + Free(tok); + Free(ftype); + *line = NULL; + return NULL; + } + Free(tok); + break; + + case StringArg: + ptr = DoGetNextToken(ptr, + &ftype->args[j].value.string_value, NULL, + ",", pstop_char); + if (!ftype->args[j].value.string_value) { + ConsoleMessage( + "%s: too few arguments\n", + builtin_functions_i->name); + *line = NULL; + Free(ftype->args[j].value.string_value); + Free(ftype); + return NULL; + } + ftype->args[j].type = + builtin_functions_i->args[j]; + break; + + case ButtonArg: + case WindowArg: + case ManagerArg: + ptr = parse_button( + ptr, &ftype->args[j], &flag, pstop_char); + if (!flag) { + ConsoleMessage( + "%s: too few arguments\n", + builtin_functions_i->name); + Free(ftype); + *line = NULL; + return NULL; + } + ftype->args[j].type = + builtin_functions_i->args[j]; + break; + + /* JmpArg can be a string or an int. However, if + * 'JmpArg' is recorded as the argument type in + * the argument array for a command, it means it + * is a string; the code for 'IntArg' is used + * instead for numbers. Note also that if the C + * function recieves a 'JmpArg' argument it + * means something went wrong, since they should + * all be translated to integer jump offsets at + * compile time. + */ + case JmpArg: + ptr = DoGetNextToken( + ptr, &tok, NULL, ",", pstop_char); + if (!tok) { + ConsoleMessage( + "%s: too few arguments\n", + builtin_functions_i->name); + Free(tok); + Free(ftype); + *line = NULL; + return NULL; + } + if (extract_int(tok, + &ftype->args[j].value.int_value) == 0) { + ftype->args[j].value.string_value = tok; + ftype->args[j].type = JmpArg; + ++JmpArgs; + } else { + ftype->args[j].type = IntArg; + Free(tok); + } + break; + + default: + ConsoleMessage( + "internal error in parse_function\n"); + Free(ftype); + *line = NULL; + return NULL; + } + } + + if (j != builtin_functions_i->numargs) { + ConsoleMessage("%s: too few arguments\n", + builtin_functions_i->name); + Free(ftype); + *line = NULL; + return NULL; + } + + *line = ptr; + return ftype; + } + + ConsoleMessage("Unknown function: %s\n", name); + Free(name); + *line = NULL; return NULL; - } - } - - if (j != builtin_functions_i->numargs) { - ConsoleMessage ("%s: too few arguments\n", builtin_functions_i->name); - Free(ftype); - *line = NULL; - return NULL; - } - - *line = ptr; - return ftype; - } - - ConsoleMessage ("Unknown function: %s\n", name); - Free (name); - - *line = NULL; - return NULL; } - /* This is O(N^2) where N = number of instructions. Seems we could do better. We'll see how this addition settles before monkeying with it */ -static Function *parse_function_list (char *line) +static Function * +parse_function_list(char *line) { - Function *ret = NULL, *tail = NULL, *f, *i; - char *token; - int jump_count, j; - char stop_char; - char c; - - JmpArgs=0; - while (line && (f = parse_function(&line, &stop_char))) { - ConsoleDebug (CONFIG, "parse_function: %p\n", f->func); - /* extra code to check for and remove a 'label' pseudo-function */ - if (f->func==builtin_label) { - /* scan backwards to fix up references */ - jump_count=0; - for (i=tail; i!=NULL; i=i->prev) { - /* scan the command arguments for a 'JmpArg' type */ - for (j=0; j<(i->numargs); ++j) { - if (i->args[j].type==JmpArg) { - /* we have a winner! */ - if (!strcasecmp(f->args[0].value.string_value, - i->args[j].value.string_value)) { - /* the label matches it, so replace with the jump_count */ - i->args[j].type = IntArg; - i->args[j].value.int_value = jump_count; - --JmpArgs; - } - } - } - ++jump_count; - } - Free(f); /* label pseudo-functions never get added to the chain */ - } else { - if (tail) - tail->next = f; - else - ret = f; - f->prev=tail; - tail = f; - } - DoGetNextToken (line, &token, NULL, ",", &c); - if (token && stop_char != ',') { - ConsoleMessage ("Bad function list, comma expected\n"); - Free (token); - return NULL; - } - stop_char = c; - Free(token); - } - - if (JmpArgs!=0) { - /* someone made a typo and we need to scan to find out what it - * was. - */ - for (f=tail; f; f=f->prev) { - for (j=0; j<(f->numargs); ++j) { - if (f->args[j].type==JmpArg) { - ConsoleMessage ("Attempt to jump to non-existant label %s; " - "aborting function list.\n", - f->args[j].value.string_value); - --JmpArgs; - } - } - } - if (JmpArgs!=0) - ConsoleMessage ( "Internal Error: JmpArgs %d not accounted for!\n", - JmpArgs ); - tail=NULL; - f=NULL; - free_function_list(ret); - ret=NULL; - return NULL; - } - if (ret == NULL) - ConsoleMessage ("No function defined\n"); - return ret; + Function *ret = NULL, *tail = NULL, *f, *i; + char *token; + int jump_count, j; + char stop_char; + char c; + + JmpArgs = 0; + while (line && (f = parse_function(&line, &stop_char))) { + ConsoleDebug(CONFIG, "parse_function: %p\n", f->func); + /* extra code to check for and remove a 'label' pseudo-function + */ + if (f->func == builtin_label) { + /* scan backwards to fix up references */ + jump_count = 0; + for (i = tail; i != NULL; i = i->prev) { + /* scan the command arguments for a 'JmpArg' + * type */ + for (j = 0; j < (i->numargs); ++j) { + if (i->args[j].type == JmpArg) { + /* we have a winner! */ + if (!strcasecmp( + f->args[0] + .value.string_value, + i->args[j] + .value + .string_value)) { + /* the label matches it, + * so replace with the + * jump_count */ + i->args[j].type = + IntArg; + i->args[j] + .value.int_value = + jump_count; + --JmpArgs; + } + } + } + ++jump_count; + } + Free(f); /* label pseudo-functions never get added to + the chain */ + } else { + if (tail) + tail->next = f; + else + ret = f; + f->prev = tail; + tail = f; + } + DoGetNextToken(line, &token, NULL, ",", &c); + if (token && stop_char != ',') { + ConsoleMessage("Bad function list, comma expected\n"); + Free(token); + return NULL; + } + stop_char = c; + Free(token); + } + + if (JmpArgs != 0) { + /* someone made a typo and we need to scan to find out what it + * was. + */ + for (f = tail; f; f = f->prev) { + for (j = 0; j < (f->numargs); ++j) { + if (f->args[j].type == JmpArg) { + ConsoleMessage( + "Attempt to jump to non-existant " + "label %s; " + "aborting function list.\n", + f->args[j].value.string_value); + --JmpArgs; + } + } + } + if (JmpArgs != 0) + ConsoleMessage( + "Internal Error: JmpArgs %d not accounted for!\n", + JmpArgs); + tail = NULL; + f = NULL; + free_function_list(ret); + ret = NULL; + return NULL; + } + if (ret == NULL) + ConsoleMessage("No function defined\n"); + return ret; } - -Binding *ParseMouseEntry (char *tline) +Binding * +ParseMouseEntry(char *tline) { - char modifiers[20],*action,*token; - Binding *new; - int button; - int n1=0,n2=0; - int mods; - - /* tline points after the key word "key" */ - action = DoGetNextToken(tline,&token, NULL, ",", NULL); - if(token != NULL) { - n1 = sscanf(token,"%d",&button); - Free(token); - } - - action = DoGetNextToken(action,&token, NULL, ",", NULL); - if(token != NULL) { - n2 = sscanf(token,"%19s",modifiers); - Free(token); - } - if((n1 != 1)||(n2 != 1)) - ConsoleMessage ("Mouse binding: Syntax error"); - - find_context(modifiers,&mods,key_modifiers,tline); - if((mods & AnyModifier)&&(mods&(~AnyModifier))) { - ConsoleMessage ("Binding specified AnyModifier and other modifers too. Excess modifiers will be ignored."); - } - - new = (Binding *)safemalloc(sizeof(Binding)); - new->IsMouse = 1; - new->Button_Key = button; - new->key_name = NULL; - new->Modifier = mods; - new->Action = stripcpy(action); - new->Function = parse_function_list (action); - new->NextBinding = NULL; - new->LastBinding = new; - - if (!new->Function) { - ConsoleMessage ("Bad action: %s\n", action); - Free (new->Action); - Free (new); - return NULL; - } - - ConsoleDebug (CONFIG, "Mouse: %d %d %s\n", new->Button_Key, - new->Modifier, new->Action); - - return new; + char modifiers[20], *action, *token; + Binding *new; + int button; + int n1 = 0, n2 = 0; + int mods; + + /* tline points after the key word "key" */ + action = DoGetNextToken(tline, &token, NULL, ",", NULL); + if (token != NULL) { + n1 = sscanf(token, "%d", &button); + Free(token); + } + + action = DoGetNextToken(action, &token, NULL, ",", NULL); + if (token != NULL) { + n2 = sscanf(token, "%19s", modifiers); + Free(token); + } + if ((n1 != 1) || (n2 != 1)) + ConsoleMessage("Mouse binding: Syntax error"); + + find_context(modifiers, &mods, key_modifiers, tline); + if ((mods & AnyModifier) && (mods & (~AnyModifier))) { + ConsoleMessage( + "Binding specified AnyModifier and other modifers " + "too. Excess modifiers will be ignored."); + } + + new = (Binding *)xmalloc(sizeof(Binding)); + new->IsMouse = 1; + new->Button_Key = button; + new->key_name = NULL; + new->Modifier = mods; + new->Action = stripcpy(action); + new->Function = parse_function_list(action); + new->NextBinding = NULL; + new->LastBinding = new; + + if (!new->Function) { + ConsoleMessage("Bad action: %s\n", action); + Free(new->Action); + Free(new); + return NULL; + } + + ConsoleDebug(CONFIG, "Mouse: %d %d %s\n", new->Button_Key, + new->Modifier, new->Action); + + return new; } -static Binding *ParseKeyEntry (char *tline) +static Binding * +ParseKeyEntry(char *tline) { - char *action,modifiers[20],key[20],*ptr, *token, *actionstring, *keystring; - Binding *new = NULL, *temp, *last = NULL; - Function *func = NULL; - int i,min,max; - int n1=0,n2=0; - KeySym keysym; - int mods; - - /* tline points after the key word "key" */ - ptr = tline; - - ptr = DoGetNextToken(ptr,&token, NULL, ",", NULL); - if(token != NULL) { - n1 = sscanf(token,"%19s",key); - Free(token); - } - - action = DoGetNextToken(ptr,&token, NULL, ",", NULL); - if(token != NULL) { - n2 = sscanf(token,"%19s",modifiers); - Free(token); - } - - if((n1 != 1)||(n2 != 1)) - ConsoleMessage ("Syntax error in line %s",tline); - - find_context(modifiers,&mods,key_modifiers,tline); - if((mods & AnyModifier)&&(mods&(~AnyModifier))) { - ConsoleMessage ("Binding specified AnyModifier and other modifers too. Excess modifiers will be ignored."); - } - - /* - * Don't let a 0 keycode go through, since that means AnyKey to the - * XGrabKey call in GrabKeys(). - */ - if ((keysym = XStringToKeysym(key)) == NoSymbol || - XKeysymToKeycode(theDisplay, keysym) == 0) { - ConsoleMessage ("Can't find keysym: %s\n", key); - return NULL; - } - - - XDisplayKeycodes(theDisplay, &min, &max); - for (i=min; i<=max; i++) { - if (XKeycodeToKeysym(theDisplay, i, 0) == keysym) { - if (!func) { - func = parse_function_list (action); - if (!func) { - ConsoleMessage ("Bad action: %s\n", action); - return NULL; + char *action, modifiers[20], key[20], *ptr, *token, *actionstring, + *keystring; + Binding *new = NULL, *temp, *last = NULL; + Function *func = NULL; + int i, min, max; + int n1 = 0, n2 = 0; + KeySym keysym; + int mods; + + /* tline points after the key word "key" */ + ptr = tline; + + ptr = DoGetNextToken(ptr, &token, NULL, ",", NULL); + if (token != NULL) { + n1 = sscanf(token, "%19s", key); + Free(token); + } + + action = DoGetNextToken(ptr, &token, NULL, ",", NULL); + if (token != NULL) { + n2 = sscanf(token, "%19s", modifiers); + Free(token); + } + + if ((n1 != 1) || (n2 != 1)) + ConsoleMessage("Syntax error in line %s", tline); + + find_context(modifiers, &mods, key_modifiers, tline); + if ((mods & AnyModifier) && (mods & (~AnyModifier))) { + ConsoleMessage( + "Binding specified AnyModifier and other modifers " + "too. Excess modifiers will be ignored."); + } + + /* + * Don't let a 0 keycode go through, since that means AnyKey to the + * XGrabKey call in GrabKeys(). + */ + if ((keysym = XStringToKeysym(key)) == NoSymbol || + XKeysymToKeycode(theDisplay, keysym) == 0) { + ConsoleMessage("Can't find keysym: %s\n", key); + return NULL; } - actionstring = stripcpy(action); - keystring = stripcpy(key); - } - temp = new; - new = (Binding *)safemalloc(sizeof(Binding)); - new->IsMouse = 0; - new->Button_Key = i; - new->key_name = keystring; - new->Modifier = mods; - new->Action = actionstring; - new->Function = func; - new->NextBinding = temp; - if (!last) { - last = new; - } - new->LastBinding = last; - - ConsoleDebug (CONFIG, "Key: %d %s %d %s\n", i, new->key_name, - mods, new->Action); - } - } - return new; + + XDisplayKeycodes(theDisplay, &min, &max); + { + Bool matched = False; + + for (i = min; i <= max; i++) { + KeySym *mapping; + int width; + + mapping = XGetKeyboardMapping(theDisplay, i, 1, &width); + if (mapping == NULL) + continue; + + for (int col = 0; col < width; col++) { + if (mapping[col] == keysym) { + if (!func) { + func = + parse_function_list(action); + if (!func) { + XFree(mapping); + ConsoleMessage( + "Bad action: %s\n", + action); + return NULL; + } + actionstring = stripcpy(action); + keystring = stripcpy(key); + } + temp = new; + new = (Binding *)xmalloc( + sizeof(Binding)); + new->IsMouse = 0; + new->Button_Key = i; + new->key_name = keystring; + new->Modifier = mods; + new->Action = actionstring; + new->Function = func; + new->NextBinding = temp; + if (!last) { + last = new; + } + new->LastBinding = last; + + ConsoleDebug(CONFIG, + "Key: %d %s %d %s\n", i, + new->key_name, mods, new->Action); + matched = True; + break; + } + } + XFree(mapping); + } + + if (!matched && func) { + Free(actionstring); + Free(keystring); + free_function_list(func); + func = NULL; + } + } + return new; } -static Binding *ParseSimpleEntry (char *tline) +static Binding * +ParseSimpleEntry(char *tline) { - Binding *new; - Function *func; - - func = parse_function_list (tline); - if (func == NULL) - return NULL; - - new = (Binding *)safemalloc (sizeof (Binding)); - new->IsMouse = 0; - new->Button_Key = 0; - new->key_name = "select"; - new->Modifier = 0; - new->Action = stripcpy (tline); - new->Function = func; - new->NextBinding = NULL; - new->LastBinding = new; - - return new; + Binding *new; + Function *func; + + func = parse_function_list(tline); + if (func == NULL) + return NULL; + + new = (Binding *)xmalloc(sizeof(Binding)); + new->IsMouse = 0; + new->Button_Key = 0; + new->key_name = "select"; + new->Modifier = 0; + new->Action = stripcpy(tline); + new->Function = func; + new->NextBinding = NULL; + new->LastBinding = new; + + return new; } -void run_binding (WinManager *man, Action action) +void +run_binding(WinManager *man, Action action) { - Binding *binding = man->bindings[action]; - ConsoleDebug (CONFIG, "run_binding:\n"); - print_bindings (binding); + Binding *binding = man->bindings[action]; + ConsoleDebug(CONFIG, "run_binding:\n"); + print_bindings(binding); - if (binding && binding->Function && binding->Function->func) { - run_function_list (binding->Function); - } + if (binding && binding->Function && binding->Function->func) { + run_function_list(binding->Function); + } } -void execute_function (char *string) +void +execute_function(char *string) { - Function *func = parse_function_list (string); - if (func == NULL) { - return; - } - else { - run_function_list (func); - free_function_list (func); - } + Function *func = parse_function_list(string); + if (func == NULL) { + return; + } else { + run_function_list(func); + free_function_list(func); + } } -static int GetConfigLineWrapper (int *fd, char **tline) +static int +GetConfigLineWrapper(int *fd, char **tline) { #if FVWM_VERSION == 1 - static char buffer[1024]; - char *temp; - - if (fgets (buffer, 1024, config_fp)) { - *tline = buffer; - temp = strchr (*tline, '\n'); - if (temp) { - *temp = '\0'; - } - else { - ConsoleMessage (stderr, "line too long\n"); - exit (1); - } - return 1; - } + static char buffer[1024]; + char *temp; + + if (fgets(buffer, 1024, config_fp)) { + *tline = buffer; + temp = strchr(*tline, '\n'); + if (temp) { + *temp = '\0'; + } else { + ConsoleMessage(stderr, "line too long\n"); + exit(1); + } + return 1; + } #else - char *temp; + char *temp; - GetConfigLine (fd, tline); - if (*tline) { - temp = strchr (*tline, '\n'); - if (temp) { - *temp = '\0'; - } - return 1; - } + GetConfigLine(fd, tline); + if (*tline) { + temp = strchr(*tline, '\n'); + if (temp) { + *temp = '\0'; + } + return 1; + } #endif - return 0; + return 0; } -static char *read_next_cmd (ReadOption flag) +static char * +read_next_cmd(ReadOption flag) { - static ReadOption status; - static char *buffer; - static char *retstring, displaced, *cur_pos; - - retstring = NULL; - if (flag != READ_LINE && !(flag & status)) - return NULL; - - switch (flag) { - case READ_LINE: - while (GetConfigLineWrapper (Fvwm_fd, &buffer)) { - cur_pos = buffer; - skip_space (&cur_pos); - if (!strncasecmp (Module, cur_pos, ModuleLen)) { - retstring = cur_pos; - cur_pos += ModuleLen; - displaced = *cur_pos; - if (displaced == '*') - status = READ_OPTION; - else if (displaced == '\0') - status = READ_LINE; - else if (iswhite (displaced)) - status = READ_ARG; - else - status = READ_LINE; - break; - } - } - break; - - case READ_OPTION: - *cur_pos = displaced; - retstring = ++cur_pos; - while (*cur_pos != '*' && !iswhite (*cur_pos)) - cur_pos++; - displaced = *cur_pos; - *cur_pos = '\0'; - if (displaced == '*') - status = READ_OPTION; - else if (displaced == '\0') - status = READ_LINE; - else if (iswhite (displaced)) - status = READ_ARG; - else - status = READ_LINE; - break; - - case READ_ARG: - *cur_pos = displaced; - skip_space (&cur_pos); - retstring = cur_pos; - while (!iswhite (*cur_pos)) - cur_pos++; - displaced = *cur_pos; - *cur_pos = '\0'; - if (displaced == '\0') - status = READ_LINE; - else if (iswhite (displaced)) - status = READ_ARG; - else - status = READ_LINE; - break; - - case READ_REST_OF_LINE: - status = READ_LINE; - *cur_pos = displaced; - skip_space (&cur_pos); - retstring = cur_pos; - break; - } - - if (retstring && retstring[0] == '\0') - retstring = NULL; - - return retstring; + static ReadOption status; + static char *buffer; + static char *retstring, displaced, *cur_pos; + + retstring = NULL; + if (flag != READ_LINE && !(flag & status)) + return NULL; + + switch (flag) { + case READ_LINE: + while (GetConfigLineWrapper(Fvwm_fd, &buffer)) { + cur_pos = buffer; + skip_space(&cur_pos); + if (!strncasecmp(Module, cur_pos, ModuleLen)) { + retstring = cur_pos; + cur_pos += ModuleLen; + displaced = *cur_pos; + if (displaced == '*') + status = READ_OPTION; + else if (displaced == '\0') + status = READ_LINE; + else if (iswhite(displaced)) + status = READ_ARG; + else + status = READ_LINE; + break; + } + } + break; + + case READ_OPTION: + *cur_pos = displaced; + retstring = ++cur_pos; + while (*cur_pos != '*' && !iswhite(*cur_pos)) + cur_pos++; + displaced = *cur_pos; + *cur_pos = '\0'; + if (displaced == '*') + status = READ_OPTION; + else if (displaced == '\0') + status = READ_LINE; + else if (iswhite(displaced)) + status = READ_ARG; + else + status = READ_LINE; + break; + + case READ_ARG: + *cur_pos = displaced; + skip_space(&cur_pos); + retstring = cur_pos; + while (!iswhite(*cur_pos)) + cur_pos++; + displaced = *cur_pos; + *cur_pos = '\0'; + if (displaced == '\0') + status = READ_LINE; + else if (iswhite(displaced)) + status = READ_ARG; + else + status = READ_LINE; + break; + + case READ_REST_OF_LINE: + status = READ_LINE; + *cur_pos = displaced; + skip_space(&cur_pos); + retstring = cur_pos; + break; + } + + if (retstring && retstring[0] == '\0') + retstring = NULL; + + return retstring; } -static char *conditional_copy_string (char **s1, char *s2) +static char * +conditional_copy_string(char **s1, char *s2) { - if (*s1) - return *s1; - else - return copy_string (s1, s2); + if (*s1) + return *s1; + else + return copy_string(s1, s2); } -static NameType parse_format_dependencies (char *format) +static NameType +parse_format_dependencies(char *format) { - NameType flags = NO_NAME; - - ConsoleDebug (CONFIG, "Parsing format: %s\n", format); - - while (*format) { - if (*format != '%') { - format++; - } - else { - format++; - if (*format == 'i') - flags |= ICON_NAME; - else if (*format == 't') - flags |= TITLE_NAME; - else if (*format == 'c') - flags |= CLASS_NAME; - else if (*format == 'r') - flags |= RESOURCE_NAME; - else if (*format != '%') - ConsoleMessage ("Bad format string: %s\n", format); - } - } + NameType flags = NO_NAME; + + ConsoleDebug(CONFIG, "Parsing format: %s\n", format); + + while (*format) { + if (*format != '%') { + format++; + } else { + format++; + if (*format == 'i') + flags |= ICON_NAME; + else if (*format == 't') + flags |= TITLE_NAME; + else if (*format == 'c') + flags |= CLASS_NAME; + else if (*format == 'r') + flags |= RESOURCE_NAME; + else if (*format != '%') + ConsoleMessage( + "Bad format string: %s\n", format); + } + } #ifdef PRINT_DEBUG - ConsoleDebug (CONFIG, "Format depends on: "); - if (flags & ICON_NAME) - ConsoleDebug (CONFIG, "Icon "); - if (flags & TITLE_NAME) - ConsoleDebug (CONFIG, "Title "); - if (flags & CLASS_NAME) - ConsoleDebug (CONFIG, "Class "); - if (flags & RESOURCE_NAME) - ConsoleDebug (CONFIG, "Resource "); - ConsoleDebug (CONFIG, "\n"); + ConsoleDebug(CONFIG, "Format depends on: "); + if (flags & ICON_NAME) + ConsoleDebug(CONFIG, "Icon "); + if (flags & TITLE_NAME) + ConsoleDebug(CONFIG, "Title "); + if (flags & CLASS_NAME) + ConsoleDebug(CONFIG, "Class "); + if (flags & RESOURCE_NAME) + ConsoleDebug(CONFIG, "Resource "); + ConsoleDebug(CONFIG, "\n"); #endif - return flags; + return flags; } -#define SET_MANAGER(manager,field,value) \ - do { \ - int id = manager; \ - if (id == -1) { \ - for (id = 0; id < globals.num_managers; id++) { \ - globals.managers[id].field = value; \ - } \ - } \ - else if (id < globals.num_managers) { \ - globals.managers[id].field = value; \ - } \ - else { \ - ConsoleMessage ("Internal error in SET_MANAGER: %d\n", id); \ - } \ - } while (0) - -static void handle_button_config (int manager, int context, char *option) +#define SET_MANAGER(manager, field, value) \ + do { \ + int id = manager; \ + if (id == -1) { \ + for (id = 0; id < globals.num_managers; id++) { \ + globals.managers[id].field = value; \ + } \ + } else if (id < globals.num_managers) { \ + globals.managers[id].field = value; \ + } else { \ + ConsoleMessage( \ + "Internal error in SET_MANAGER: %d\n", id); \ + } \ + } while (0) + +static void +handle_button_config(int manager, int context, char *option) { - char *p; - ButtonState state; - - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need argument to %s\n", option); - return; - } - else if (!strcasecmp (p, "flat")) { - state = BUTTON_FLAT; - } - else if (!strcasecmp (p, "up")) { - state = BUTTON_UP; - } - else if (!strcasecmp (p, "down")) { - state = BUTTON_DOWN; - } - else if (!strcasecmp (p, "raisededge")) { - state = BUTTON_EDGEUP; - } - else if (!strcasecmp (p, "sunkedge")) { - state = BUTTON_EDGEDOWN; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("This isn't a valid button state: %s\n", p); - return; - } - ConsoleDebug (CONFIG, "Setting buttonState[%s] to %s\n", - contextDefaults[context].name, p); - SET_MANAGER (manager, buttonState[context], state); - - /* check for optional fore color */ - p = read_next_cmd (READ_ARG); - if ( !p ) - return; - - SET_MANAGER (manager, foreColorName[context], - copy_string (&globals.managers[id].foreColorName[context], p)); - - /* check for optional back color */ - p = read_next_cmd (READ_ARG); - if ( !p ) - return; - - ConsoleDebug (CONFIG, "Setting backColorName[%s] to %s\n", - contextDefaults[context].name, p); - SET_MANAGER (manager, backColorName[context], - copy_string (&globals.managers[id].backColorName[context], p)); -} - -void read_in_resources (char *file) -{ - char *p, *q; - int i, n, manager; - char *option1; - Binding *binding; - Resolution r; - - if (!init_config_file (file)) - return; - - while ((p = read_next_cmd (READ_LINE))) { - ConsoleDebug (CONFIG, "line: %s\n", p); - save_current_line (p); - - option1 = read_next_cmd (READ_OPTION); - if (option1 == NULL) - continue; - - ConsoleDebug (CONFIG, "option1: %s\n", option1); - if (!strcasecmp (option1, "nummanagers")) { - /* If in transient mode, just use the default of 1 manager */ - if (!globals.transient) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - if (extract_int (p, &n) == 0) { - ConsoleMessage ("This is not a number: %s\n", p); - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - if (n > 0) { - allocate_managers (n); - ConsoleDebug (CONFIG, "num managers: %d\n", n); - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("You can't have zero managers. " - "I'll give you one.\n"); - allocate_managers (1); - } - } - } - else { - /* these all can specify a specific manager */ - - if (globals.managers == NULL) { - ConsoleDebug (CONFIG, "I'm assuming you only want one manager\n"); - allocate_managers (1); - } - - manager = 0; - - if (option1[0] >= '0' && option1[0] <= '9') { - if (globals.transient) { - ConsoleDebug (CONFIG, "In transient mode. Ignoring this line\n"); - continue; - } - if (extract_int (option1, &manager) == 0 || - manager <= 0 || manager > globals.num_managers) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("This is not a valid manager: %s.\n", option1); - manager = 0; - } - option1 = read_next_cmd (READ_OPTION); - if (!option1) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - } - else if (!strcasecmp (option1, "transient")) { - if (globals.transient) { - ConsoleDebug (CONFIG, "Transient manager config line\n"); - manager = 1; - option1 = read_next_cmd (READ_OPTION); - if (!option1) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - } - else { - ConsoleDebug (CONFIG, "Not in transient mode. Ignoring this line\n"); - continue; - } - } - - manager--; /* -1 means global */ - - ConsoleDebug (CONFIG, "Applying %s to manager %d\n", option1, manager); - - if (!strcasecmp (option1, "action")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - - if (!strcasecmp (p, "mouse")) { - i = MOUSE; - } - else if (!strcasecmp (p, "key")) { - i = KEYPRESS; - } - else if (!strcasecmp (p, "select")) { - i = SELECT; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("This isn't a valid action name: %s\n", p); - continue; - } + char *p; + ButtonState state; - q = read_next_cmd (READ_REST_OF_LINE); - if (!q) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need an action\n"); - continue; - } - - switch (i) { - case MOUSE: - binding = ParseMouseEntry (q); - break; - - case KEYPRESS: - binding = ParseKeyEntry (q); - break; - - case SELECT: - binding = ParseSimpleEntry (q); - break; - } - - if (binding == NULL) { - ConsoleMessage ("Offending line: %s\n", current_line); - ConsoleMessage ("Bad action\n"); - continue; - } - - if (manager == -1) { - int j; - for (j = 0; j < globals.num_managers; j++) { - add_to_binding (&globals.managers[j].bindings[i], binding); - } - } - else if (manager < globals.num_managers) { - add_to_binding (&globals.managers[manager].bindings[i], binding); - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("There's no manager %d\n", manager); - } - } - else if (!strcasecmp (option1, "background")) { - p = read_next_cmd (READ_ARG); + p = read_next_cmd(READ_ARG); if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - ConsoleDebug (CONFIG, "default background: %s\n", p); - - for ( i = 0; i < NUM_CONTEXTS; i++ ) - SET_MANAGER (manager, backColorName[i], - conditional_copy_string (&globals.managers[id].backColorName[i], - p)); - } - else if (!strcasecmp (option1, "buttongeometry")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } + ConsoleMessage("Bad line: %s\n", current_line); + ConsoleMessage("Need argument to %s\n", option); + return; + } else if (!strcasecmp(p, "flat")) { + state = BUTTON_FLAT; + } else if (!strcasecmp(p, "up")) { + state = BUTTON_UP; + } else if (!strcasecmp(p, "down")) { + state = BUTTON_DOWN; + } else if (!strcasecmp(p, "raisededge")) { + state = BUTTON_EDGEUP; + } else if (!strcasecmp(p, "sunkedge")) { + state = BUTTON_EDGEDOWN; + } else { + ConsoleMessage("Bad line: %s\n", current_line); + ConsoleMessage("This isn't a valid button state: %s\n", p); + return; + } + ConsoleDebug(CONFIG, "Setting buttonState[%s] to %s\n", + contextDefaults[context].name, p); + SET_MANAGER(manager, buttonState[context], state); + + /* check for optional fore color */ + p = read_next_cmd(READ_ARG); + if (!p) + return; + + SET_MANAGER(manager, foreColorName[context], + copy_string(&globals.managers[id].foreColorName[context], p)); + + /* check for optional back color */ + p = read_next_cmd(READ_ARG); + if (!p) + return; + + ConsoleDebug(CONFIG, "Setting backColorName[%s] to %s\n", + contextDefaults[context].name, p); + SET_MANAGER(manager, backColorName[context], + copy_string(&globals.managers[id].backColorName[context], p)); +} - SET_MANAGER (manager, button_geometry_str, - copy_string (&globals.managers[id].button_geometry_str, p)); - } - else if (!strcasecmp (option1, "dontshow")) { - char *token = NULL; - p = read_next_cmd (READ_REST_OF_LINE); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - p = DoGetNextToken (p, &token, NULL, ",", NULL); - if (!token) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - do { - ConsoleDebug (CONFIG, "dont show: %s\n", token); - if (manager == -1) { - int i; - for (i = 0; i < globals.num_managers; i++) - add_to_stringlist (&globals.managers[i].dontshow, token); - } - else { - add_to_stringlist (&globals.managers[manager].dontshow, token); - } - Free (token); - p = DoGetNextToken (p, &token, NULL, ",", NULL); - } while (token); - if (token) - Free(token); - } - else if (!strcasecmp (option1, "drawicons")) { +void +read_in_resources(char *file) +{ + char *p, *q; + int i, n, manager; + char *option1; + Binding *binding; + Resolution r; + + if (!init_config_file(file)) + return; + + while ((p = read_next_cmd(READ_LINE))) { + ConsoleDebug(CONFIG, "line: %s\n", p); + save_current_line(p); + + option1 = read_next_cmd(READ_OPTION); + if (option1 == NULL) + continue; + + ConsoleDebug(CONFIG, "option1: %s\n", option1); + if (!strcasecmp(option1, "nummanagers")) { + /* If in transient mode, just use the default of 1 + * manager */ + if (!globals.transient) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + if (extract_int(p, &n) == 0) { + ConsoleMessage( + "This is not a number: %s\n", p); + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + if (n > 0) { + allocate_managers(n); + ConsoleDebug( + CONFIG, "num managers: %d\n", n); + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "You can't have zero managers. " + "I'll give you one.\n"); + allocate_managers(1); + } + } + } else { + /* these all can specify a specific manager */ + + if (globals.managers == NULL) { + ConsoleDebug(CONFIG, + "I'm assuming you only want one manager\n"); + allocate_managers(1); + } + + manager = 0; + + if (option1[0] >= '0' && option1[0] <= '9') { + if (globals.transient) { + ConsoleDebug(CONFIG, + "In transient mode. " + "Ignoring this line\n"); + continue; + } + if (extract_int(option1, &manager) == 0 || + manager <= 0 || + manager > globals.num_managers) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage("This is not a valid " + "manager: %s.\n", + option1); + manager = 0; + } + option1 = read_next_cmd(READ_OPTION); + if (!option1) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + } else if (!strcasecmp(option1, "transient")) { + if (globals.transient) { + ConsoleDebug(CONFIG, + "Transient manager config line\n"); + manager = 1; + option1 = read_next_cmd(READ_OPTION); + if (!option1) { + ConsoleMessage("Bad line: %s\n", + current_line); + continue; + } + } else { + ConsoleDebug(CONFIG, + "Not in transient mode. " + "Ignoring this line\n"); + continue; + } + } + + manager--; /* -1 means global */ + + ConsoleDebug(CONFIG, "Applying %s to manager %d\n", + option1, manager); + + if (!strcasecmp(option1, "action")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + + if (!strcasecmp(p, "mouse")) { + i = MOUSE; + } else if (!strcasecmp(p, "key")) { + i = KEYPRESS; + } else if (!strcasecmp(p, "select")) { + i = SELECT; + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage("This isn't a valid " + "action name: %s\n", + p); + continue; + } + + q = read_next_cmd(READ_REST_OF_LINE); + if (!q) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage("Need an action\n"); + continue; + } + + switch (i) { + case MOUSE: + binding = ParseMouseEntry(q); + break; + + case KEYPRESS: + binding = ParseKeyEntry(q); + break; + + case SELECT: + binding = ParseSimpleEntry(q); + break; + } + + if (binding == NULL) { + ConsoleMessage("Offending line: %s\n", + current_line); + ConsoleMessage("Bad action\n"); + continue; + } + + if (manager == -1) { + int j; + for (j = 0; j < globals.num_managers; + j++) { + add_to_binding( + &globals.managers[j] + .bindings[i], + binding); + } + } else if (manager < globals.num_managers) { + add_to_binding( + &globals.managers[manager] + .bindings[i], + binding); + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "There's no manager %d\n", manager); + } + } else if (!strcasecmp(option1, "background")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + ConsoleDebug( + CONFIG, "default background: %s\n", p); + + for (i = 0; i < NUM_CONTEXTS; i++) + SET_MANAGER(manager, backColorName[i], + conditional_copy_string( + &globals.managers[id] + .backColorName[i], + p)); + } else if (!strcasecmp(option1, "buttongeometry")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + + SET_MANAGER(manager, button_geometry_str, + copy_string(&globals.managers[id] + .button_geometry_str, + p)); + } else if (!strcasecmp(option1, "dontshow")) { + char *token = NULL; + p = read_next_cmd(READ_REST_OF_LINE); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + p = DoGetNextToken(p, &token, NULL, ",", NULL); + if (!token) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + do { + ConsoleDebug( + CONFIG, "dont show: %s\n", token); + if (manager == -1) { + int i; + for (i = 0; + i < globals.num_managers; + i++) + add_to_stringlist( + &globals.managers[i] + .dontshow, + token); + } else { + add_to_stringlist( + &globals.managers[manager] + .dontshow, + token); + } + Free(token); + p = DoGetNextToken( + p, &token, NULL, ",", NULL); + } while (token); + if (token) + Free(token); + } else if (!strcasecmp(option1, "drawicons")) { #ifdef MINI_ICONS - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need argument to drawicons\n"); - continue; - } - if (!strcasecmp (p, "true")) { - i = 1; - } - /* [NFM 3 Dec 97] added support for FvwmIconMan*drawicons "always" */ - else if (!strcasecmp (p, "always")) { - i = 2; - } - else if (!strcasecmp (p, "false")) { - i = 0; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("What is this: %s?\n", p); - continue; - } - ConsoleDebug (CONFIG, "Setting drawicons to: %d\n", i); - SET_MANAGER (manager, draw_icons, i); + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "Need argument to drawicons\n"); + continue; + } + if (!strcasecmp(p, "true")) { + i = 1; + } + /* [NFM 3 Dec 97] added support for + FvwmIconMan*drawicons "always" */ + else if (!strcasecmp(p, "always")) { + i = 2; + } else if (!strcasecmp(p, "false")) { + i = 0; + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "What is this: %s?\n", p); + continue; + } + ConsoleDebug( + CONFIG, "Setting drawicons to: %d\n", i); + SET_MANAGER(manager, draw_icons, i); #else - ConsoleMessage ("DrawIcons support not compiled in\n"); + ConsoleMessage( + "DrawIcons support not compiled in\n"); #endif - } - else if (!strcasecmp (option1, "followfocus")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need argument to followfocus\n"); - continue; - } - if (!strcasecmp (p, "true")) { - i = 1; - } - else if (!strcasecmp (p, "false")) { - i = 0; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("What is this: %s?\n", p); - continue; - } - ConsoleDebug (CONFIG, "Setting followfocus to: %d\n", i); - SET_MANAGER (manager, followFocus, i); - } - else if (!strcasecmp (option1, "font")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - ConsoleDebug (CONFIG, "font: %s\n", p); - - SET_MANAGER (manager, fontname, - copy_string (&globals.managers[id].fontname, p)); - } - else if (!strcasecmp (option1, "foreground")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - ConsoleDebug (CONFIG, "default foreground: %s\n", p); - - for ( i = 0; i < NUM_CONTEXTS; i++ ) - SET_MANAGER (manager, foreColorName[i], - conditional_copy_string (&globals.managers[id].foreColorName[i], - p)); - } - else if (!strcasecmp (option1, "format")) { - char *token; - NameType flags; - - p = read_next_cmd (READ_REST_OF_LINE); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - DoGetNextToken (p, &token, NULL, ",", NULL); - if (!token) - { - token = (char *)safemalloc(1); - *token = 0; - } - - SET_MANAGER (manager, formatstring, - copy_string (&globals.managers[id].formatstring, token)); - flags = parse_format_dependencies (token); - SET_MANAGER (manager, format_depend, flags); - Free (token); - } - else if (!strcasecmp (option1, "geometry")) { - ConsoleMessage ("Geometry option no longer supported.\n"); - ConsoleMessage ("Use ManagerGeometry and ButtonGeometry.\n"); - } - else if (!strcasecmp (option1, "iconname")) { - char *token; - p = read_next_cmd (READ_REST_OF_LINE); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - DoGetNextToken (p, &token, NULL, ",", NULL); - if (!token) - { - token = (char *)safemalloc(1); - *token = 0; - } - - SET_MANAGER (manager, iconname, - copy_string (&globals.managers[id].iconname, token)); - Free (token); - } - else if (!strcasecmp (option1, "managergeometry")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - - SET_MANAGER (manager, geometry_str, - copy_string (&globals.managers[id].geometry_str, p)); - } - else if (!strcasecmp (option1, "resolution")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - ConsoleDebug (CONFIG, "resolution: %s\n", p); - if (!strcasecmp (p, "global")) - r = SHOW_GLOBAL; - else if (!strcasecmp (p, "desk")) - r = SHOW_DESKTOP; - else if (!strcasecmp (p, "page")) - r = SHOW_PAGE; - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("What kind of resolution is this?\n"); - continue; - } - - SET_MANAGER (manager, res, r); - } - else if (!strcasecmp (option1, "shape")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need argument to followfocus\n"); - continue; - } - if (!strcasecmp (p, "true")) { - i = 1; - } - else if (!strcasecmp (p, "false")) { - i = 0; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("What is this: %s?\n", p); - continue; - } - if (i && globals.shapes_supported == 0) { - ConsoleMessage ("Shape support not compiled in\n"); - continue; - } - ConsoleDebug (CONFIG, "Setting shape to: %d\n", i); - SET_MANAGER (manager, shaped, i); - } - else if (!strcasecmp (option1, "show")) { - char *token = NULL; - p = read_next_cmd (READ_REST_OF_LINE); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - p = DoGetNextToken (p, &token, NULL, ",", NULL); - if (!token) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - do { - ConsoleDebug (CONFIG, "show: %s\n", token); - if (manager == -1) { - int i; - for (i = 0; i < globals.num_managers; i++) - add_to_stringlist (&globals.managers[i].show, token); - } - else { - add_to_stringlist (&globals.managers[manager].show, token); - } - Free (token); - p = DoGetNextToken (p, &token, NULL, ",", NULL); - } while (token); - if (token) - Free(token); - } - else if (!strcasecmp (option1, "showtitle")) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("showtitle is no longer an option. Use format\n"); - continue; - } - else if (!strcasecmp (option1, "sort")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need argument to sort\n"); - continue; - } - if (!strcasecmp (p, "name")) { - i = SortName; - } - else if (!strcasecmp (p, "namewithcase")) { - i = SortNameCase; - } - else if (!strcasecmp (p, "id")) { - i = SortId; - } - else if (!strcasecmp (p, "none")) { - i = SortNone; - } - else if (!strcasecmp (p, "false") || !strcasecmp (p, "true")) { - /* Old options */ - ConsoleMessage ("FvwmIconMan*sort option no longer takes " - "true or false value\n" - "Please read the latest manpage\n"); - continue; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("What is this: %s?\n", p); - continue; - } - ConsoleDebug (CONFIG, "Setting sort to: %d\n", i); - SET_MANAGER (manager, sort, i); - } - else if (!strcasecmp (option1, "title")) { - char *token; - p = read_next_cmd (READ_REST_OF_LINE); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - DoGetNextToken (p, &token, NULL, ",", NULL); - if (!token) - { - token = (char *)safemalloc(1); - *token = 0; - } - - SET_MANAGER (manager, titlename, - copy_string (&globals.managers[id].titlename, token)); - Free (token); - } - else if (!strcasecmp (option1, "plainButton")) { - handle_button_config (manager, PLAIN_CONTEXT, option1); - } - else if (!strcasecmp (option1, "selectButton")) { - handle_button_config (manager, SELECT_CONTEXT, option1); - } - else if (!strcasecmp (option1, "focusButton")) { - handle_button_config (manager, FOCUS_CONTEXT, option1); - } - else if (!strcasecmp (option1, "focusandselectButton")) { - handle_button_config (manager, FOCUS_SELECT_CONTEXT, option1); - } - else if (!strcasecmp (option1, "titlebutton")) { - handle_button_config (manager, TITLE_CONTEXT, option1); - } - else if (!strcasecmp (option1, "usewinlist")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need argument to usewinlist\n"); - continue; - } - if (!strcasecmp (p, "true")) { - i = 1; - } - else if (!strcasecmp (p, "false")) { - i = 0; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("What is this: %s?\n", p); - continue; - } - ConsoleDebug (CONFIG, "Setting usewinlist to: %d\n", i); - SET_MANAGER (manager, usewinlist, i); - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Unknown option: %s\n", p); - } - } - } - - if (globals.managers == NULL) { - ConsoleDebug (CONFIG, "I'm assuming you only want one manager\n"); - allocate_managers (1); - } - print_managers(); - close_config_file(); + } else if (!strcasecmp(option1, "followfocus")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "Need argument to followfocus\n"); + continue; + } + if (!strcasecmp(p, "true")) { + i = 1; + } else if (!strcasecmp(p, "false")) { + i = 0; + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "What is this: %s?\n", p); + continue; + } + ConsoleDebug( + CONFIG, "Setting followfocus to: %d\n", i); + SET_MANAGER(manager, followFocus, i); + } else if (!strcasecmp(option1, "font")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + ConsoleDebug(CONFIG, "font: %s\n", p); + + SET_MANAGER(manager, fontname, + copy_string( + &globals.managers[id].fontname, p)); + } else if (!strcasecmp(option1, "foreground")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + ConsoleDebug( + CONFIG, "default foreground: %s\n", p); + + for (i = 0; i < NUM_CONTEXTS; i++) + SET_MANAGER(manager, foreColorName[i], + conditional_copy_string( + &globals.managers[id] + .foreColorName[i], + p)); + } else if (!strcasecmp(option1, "format")) { + char *token; + NameType flags; + + p = read_next_cmd(READ_REST_OF_LINE); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + DoGetNextToken(p, &token, NULL, ",", NULL); + if (!token) { + token = (char *)xmalloc(1); + *token = 0; + } + + SET_MANAGER(manager, formatstring, + copy_string( + &globals.managers[id].formatstring, + token)); + flags = parse_format_dependencies(token); + SET_MANAGER(manager, format_depend, flags); + Free(token); + } else if (!strcasecmp(option1, "geometry")) { + ConsoleMessage( + "Geometry option no longer supported.\n"); + ConsoleMessage("Use ManagerGeometry and " + "ButtonGeometry.\n"); + } else if (!strcasecmp(option1, "iconname")) { + char *token; + p = read_next_cmd(READ_REST_OF_LINE); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + DoGetNextToken(p, &token, NULL, ",", NULL); + if (!token) { + token = (char *)xmalloc(1); + *token = 0; + } + + SET_MANAGER(manager, iconname, + copy_string( + &globals.managers[id].iconname, token)); + Free(token); + } else if (!strcasecmp(option1, "managergeometry")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + + SET_MANAGER(manager, geometry_str, + copy_string( + &globals.managers[id].geometry_str, p)); + } else if (!strcasecmp(option1, "resolution")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + ConsoleDebug(CONFIG, "resolution: %s\n", p); + if (!strcasecmp(p, "global")) + r = SHOW_GLOBAL; + else if (!strcasecmp(p, "desk")) + r = SHOW_DESKTOP; + else if (!strcasecmp(p, "page")) + r = SHOW_PAGE; + else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage("What kind of " + "resolution is this?\n"); + continue; + } + + SET_MANAGER(manager, res, r); + } else if (!strcasecmp(option1, "shape")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "Need argument to followfocus\n"); + continue; + } + if (!strcasecmp(p, "true")) { + i = 1; + } else if (!strcasecmp(p, "false")) { + i = 0; + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "What is this: %s?\n", p); + continue; + } + if (i && globals.shapes_supported == 0) { + ConsoleMessage( + "Shape support not compiled in\n"); + continue; + } + ConsoleDebug( + CONFIG, "Setting shape to: %d\n", i); + SET_MANAGER(manager, shaped, i); + } else if (!strcasecmp(option1, "show")) { + char *token = NULL; + p = read_next_cmd(READ_REST_OF_LINE); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + p = DoGetNextToken(p, &token, NULL, ",", NULL); + if (!token) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + do { + ConsoleDebug( + CONFIG, "show: %s\n", token); + if (manager == -1) { + int i; + for (i = 0; + i < globals.num_managers; + i++) + add_to_stringlist( + &globals.managers[i] + .show, + token); + } else { + add_to_stringlist( + &globals.managers[manager] + .show, + token); + } + Free(token); + p = DoGetNextToken( + p, &token, NULL, ",", NULL); + } while (token); + if (token) + Free(token); + } else if (!strcasecmp(option1, "showtitle")) { + ConsoleMessage("Bad line: %s\n", current_line); + ConsoleMessage("showtitle is no longer an " + "option. Use format\n"); + continue; + } else if (!strcasecmp(option1, "sort")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "Need argument to sort\n"); + continue; + } + if (!strcasecmp(p, "name")) { + i = SortName; + } else if (!strcasecmp(p, "namewithcase")) { + i = SortNameCase; + } else if (!strcasecmp(p, "id")) { + i = SortId; + } else if (!strcasecmp(p, "none")) { + i = SortNone; + } else if (!strcasecmp(p, "false") || + !strcasecmp(p, "true")) { + /* Old options */ + ConsoleMessage( + "FvwmIconMan*sort option no longer " + "takes " + "true or false value\n" + "Please read the latest manpage\n"); + continue; + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "What is this: %s?\n", p); + continue; + } + ConsoleDebug( + CONFIG, "Setting sort to: %d\n", i); + SET_MANAGER(manager, sort, i); + } else if (!strcasecmp(option1, "title")) { + char *token; + p = read_next_cmd(READ_REST_OF_LINE); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + DoGetNextToken(p, &token, NULL, ",", NULL); + if (!token) { + token = (char *)xmalloc(1); + *token = 0; + } + + SET_MANAGER(manager, titlename, + copy_string(&globals.managers[id].titlename, + token)); + Free(token); + } else if (!strcasecmp(option1, "plainButton")) { + handle_button_config( + manager, PLAIN_CONTEXT, option1); + } else if (!strcasecmp(option1, "selectButton")) { + handle_button_config( + manager, SELECT_CONTEXT, option1); + } else if (!strcasecmp(option1, "focusButton")) { + handle_button_config( + manager, FOCUS_CONTEXT, option1); + } else if (!strcasecmp( + option1, "focusandselectButton")) { + handle_button_config( + manager, FOCUS_SELECT_CONTEXT, option1); + } else if (!strcasecmp(option1, "titlebutton")) { + handle_button_config( + manager, TITLE_CONTEXT, option1); + } else if (!strcasecmp(option1, "usewinlist")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "Need argument to usewinlist\n"); + continue; + } + if (!strcasecmp(p, "true")) { + i = 1; + } else if (!strcasecmp(p, "false")) { + i = 0; + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "What is this: %s?\n", p); + continue; + } + ConsoleDebug( + CONFIG, "Setting usewinlist to: %d\n", i); + SET_MANAGER(manager, usewinlist, i); + } else { + ConsoleMessage("Bad line: %s\n", current_line); + ConsoleMessage("Unknown option: %s\n", p); + } + } + } + + if (globals.managers == NULL) { + ConsoleDebug( + CONFIG, "I'm assuming you only want one manager\n"); + allocate_managers(1); + } + print_managers(); + close_config_file(); } - Index: fvwm/modules/FvwmIconMan/readconfig.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/readconfig.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/readconfig.h --- fvwm/modules/FvwmIconMan/readconfig.h +++ fvwm/modules/FvwmIconMan/readconfig.h @@ -1,18 +1,25 @@ +#ifndef READCONFIG_H +#define READCONFIG_H + +#include "FvwmIconMan.h" + typedef enum { - READ_LINE = 1, - READ_OPTION = 2, - READ_ARG = 4, - READ_REST_OF_LINE = 12 + READ_LINE = 1, + READ_OPTION = 2, + READ_ARG = 4, + READ_REST_OF_LINE = 12 } ReadOption; -extern void read_in_resources (char *file); -extern void print_bindings (Binding *list); -extern void print_args (int numargs, BuiltinArg *args); -extern Binding *ParseMouseEntry (char *tline); +extern void read_in_resources(char *file); +extern void print_bindings(Binding *list); +extern void print_args(int numargs, BuiltinArg *args); +extern Binding *ParseMouseEntry(char *tline); -extern void run_function_list (Function *func); -extern void run_binding (WinManager *man, Action action); +extern void run_function_list(Function *func); +extern void run_binding(WinManager *man, Action action); -#define MODS_USED (ShiftMask | ControlMask | Mod1Mask | \ - Mod2Mask| Mod3Mask| Mod4Mask| Mod5Mask) +#define MODS_USED \ + (ShiftMask | ControlMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask |\ + Mod5Mask) +#endif /* READCONFIG_H */ Index: fvwm/modules/FvwmIconMan/winlist.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/winlist.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/winlist.c --- fvwm/modules/FvwmIconMan/winlist.c +++ fvwm/modules/FvwmIconMan/winlist.c @@ -1,378 +1,424 @@ #include +#include + #include "FvwmIconMan.h" static char const rcsid[] = - "$Id: winlist.c,v 1.1.1.1 2006/11/26 10:53:50 matthieu Exp $"; + "$Id: winlist.c,v 1.1.1.1 2006/11/26 10:53:50 matthieu Exp $"; #define HASHTAB_SIZE 257 typedef WinList HashTab[HASHTAB_SIZE]; static HashTab hash_tab; -void print_stringlist (StringList *list) +void +print_stringlist(StringList *list) { - StringEl *p; - char *s; - - ConsoleDebug (WINLIST, "\tmask = 0x%x\n", list->mask); - for (p = list->list; p; p = p->next) { - switch (p->type) { - case ALL_NAME: - s = "all"; - break; - - case TITLE_NAME: - s = "title"; - break; - - case ICON_NAME: - s = "icon"; - break; - - case RESOURCE_NAME: - s = "resource"; - break; - - case CLASS_NAME: - s = "class"; - break; - - default: - s = "unknown type"; - } - ConsoleDebug (WINLIST, "\t%s = %s\n", s, p->string); - } + StringEl *p; + char *s; + + ConsoleDebug(WINLIST, "\tmask = 0x%x\n", list->mask); + for (p = list->list; p; p = p->next) { + switch (p->type) { + case ALL_NAME: + s = "all"; + break; + + case TITLE_NAME: + s = "title"; + break; + + case ICON_NAME: + s = "icon"; + break; + + case RESOURCE_NAME: + s = "resource"; + break; + + case CLASS_NAME: + s = "class"; + break; + + default: + s = "unknown type"; + } + ConsoleDebug(WINLIST, "\t%s = %s\n", s, p->string); + } } -void add_to_stringlist (StringList *list, char *s) +void +add_to_stringlist(StringList *list, char *s) { - StringEl *new; - NameType type; - char *pat; - - ConsoleDebug (WINLIST, "In add_to_stringlist: %s\n", s); - - pat = strchr (s, '='); - if (pat) { - *pat++ = '\0'; - if (!strcasecmp (s, "icon")) - type = ICON_NAME; - else if (!strcasecmp (s, "title")) - type = TITLE_NAME; - else if (!strcasecmp (s, "resource")) - type = RESOURCE_NAME; - else if (!strcasecmp (s, "class")) - type = CLASS_NAME; - else { - ConsoleMessage ("Bad element in show/dontshow list: %s\n", s); - return; - } - } - else { - pat = s; - type = ALL_NAME; - } - - ConsoleDebug (WINLIST, "add_to_stringlist: %s %s\n", - type == ALL_NAME ? "all" : s, pat); - - new = (StringEl *)safemalloc (sizeof (StringEl)); - new->string = (char *)safemalloc ((strlen (pat) + 1) * sizeof (char)); - new->type = type; - - strcpy (new->string, pat); - new->next = list->list; - if (list->list) - list->mask |= type; - else - list->mask = type; - list->list = new; - - ConsoleDebug (WINLIST, "Exiting add_to_stringlist\n"); + StringEl *new; + NameType type; + char *pat; + + ConsoleDebug(WINLIST, "In add_to_stringlist: %s\n", s); + + pat = strchr(s, '='); + if (pat) { + *pat++ = '\0'; + if (!strcasecmp(s, "icon")) + type = ICON_NAME; + else if (!strcasecmp(s, "title")) + type = TITLE_NAME; + else if (!strcasecmp(s, "resource")) + type = RESOURCE_NAME; + else if (!strcasecmp(s, "class")) + type = CLASS_NAME; + else { + ConsoleMessage( + "Bad element in show/dontshow list: %s\n", s); + return; + } + } else { + pat = s; + type = ALL_NAME; + } + + ConsoleDebug(WINLIST, "add_to_stringlist: %s %s\n", + type == ALL_NAME ? "all" : s, pat); + + new = (StringEl *)xmalloc(sizeof(StringEl)); + size_t pat_len = strlen(pat); + new->string = (char *)xmalloc((pat_len + 1) * sizeof(char)); + new->type = type; + + strlcpy(new->string, pat, pat_len + 1); + new->next = list->list; + if (list->list) + list->mask |= type; + else + list->mask = type; + list->list = new; + + ConsoleDebug(WINLIST, "Exiting add_to_stringlist\n"); } -static int matches_string (NameType type, char *pattern, char *tname, - char *iname, char *rname, char *cname) +static int +stringlist_requires_name(const StringList *list, NameType type) { - int ans = 0; - - ConsoleDebug (WINLIST, "matches_string: type: 0x%x pattern: %s\n", - type, pattern); - ConsoleDebug (WINLIST, "\tstrings: %s:%s %s:%s\n", tname, iname, - rname, cname); - - if (tname && (type == ALL_NAME || type == TITLE_NAME)) { - ans |= matchWildcards (pattern, tname); - } - if (iname && (type == ALL_NAME || type == ICON_NAME)) { - ans |= matchWildcards (pattern, iname); - } - if (rname && (type == ALL_NAME || type == RESOURCE_NAME)) { - ans |= matchWildcards (pattern, rname); - } - if (cname && (type == ALL_NAME || type == CLASS_NAME)) { - ans |= matchWildcards (pattern, cname); - } - - ConsoleDebug (WINLIST, "\tmatches_string: %d\n", ans); - return ans; + StringEl *p; + + if (!list) + return 0; + + for (p = list->list; p; p = p->next) { + if (p->type == type) + return 1; + } + + return 0; } -static int iconmanager_show (WinManager *man, char *tname, char *iname, - char *rname, char *cname) +static int +matches_string(NameType type, char *pattern, char *tname, char *iname, + char *rname, char *cname) { - StringEl *string; - int in_showlist = 0, in_dontshowlist = 0; + int ans = 0; + + ConsoleDebug( + WINLIST, "matches_string: type: 0x%x pattern: %s\n", type, pattern); + ConsoleDebug( + WINLIST, "\tstrings: %s:%s %s:%s\n", tname, iname, rname, cname); + + if (tname && (type == ALL_NAME || type == TITLE_NAME)) { + ans |= matchWildcards(pattern, tname); + } + if (iname && (type == ALL_NAME || type == ICON_NAME)) { + ans |= matchWildcards(pattern, iname); + } + if (rname && (type == ALL_NAME || type == RESOURCE_NAME)) { + ans |= matchWildcards(pattern, rname); + } + if (cname && (type == ALL_NAME || type == CLASS_NAME)) { + ans |= matchWildcards(pattern, cname); + } - assert (man); + ConsoleDebug(WINLIST, "\tmatches_string: %d\n", ans); + return ans; +} + +static int +iconmanager_show( + WinManager *man, char *tname, char *iname, char *rname, char *cname) +{ + StringEl *string; + int in_showlist = 0, in_dontshowlist = 0; + + assert(man); #ifdef PRINT_DEBUG - ConsoleDebug (WINLIST, "In iconmanager_show: %s:%s : %s %s\n", tname, iname, - rname, cname); - ConsoleDebug (WINLIST, "dontshow:\n"); - print_stringlist (&man->dontshow); - ConsoleDebug (WINLIST, "show:\n"); - print_stringlist (&man->show); + ConsoleDebug(WINLIST, "In iconmanager_show: %s:%s : %s %s\n", tname, + iname, rname, cname); + ConsoleDebug(WINLIST, "dontshow:\n"); + print_stringlist(&man->dontshow); + ConsoleDebug(WINLIST, "show:\n"); + print_stringlist(&man->show); #endif /*PRINT_DEBUG*/ - for (string = man->dontshow.list; string; string = string->next) { - ConsoleDebug (WINLIST, "Matching: %s\n", string->string); - if (matches_string (string->type, string->string, tname, iname, - rname, cname)) { - ConsoleDebug (WINLIST, "Dont show\n"); - in_dontshowlist = 1; - break; - } - } - - if (!in_dontshowlist) { - if (man->show.list == NULL) { - in_showlist = 1; - } - else { - for (string = man->show.list; string; string = string->next) { - ConsoleDebug (WINLIST, "Matching: %s\n", string->string); - if (matches_string (string->type, string->string, tname, iname, - rname, cname)) { - ConsoleDebug (WINLIST, "Show\n"); - in_showlist = 1; - break; + for (string = man->dontshow.list; string; string = string->next) { + ConsoleDebug(WINLIST, "Matching: %s\n", string->string); + if (matches_string(string->type, string->string, tname, iname, + rname, cname)) { + ConsoleDebug(WINLIST, "Dont show\n"); + in_dontshowlist = 1; + break; + } + } + + if (!in_dontshowlist) { + if (man->show.list == NULL) { + in_showlist = 1; + } else { + for (string = man->show.list; string; + string = string->next) { + ConsoleDebug( + WINLIST, "Matching: %s\n", string->string); + if (matches_string(string->type, string->string, + tname, iname, rname, cname)) { + ConsoleDebug(WINLIST, "Show\n"); + in_showlist = 1; + break; + } + } + } } - } - } - } - ConsoleDebug (WINLIST, "returning: %d %d %d\n", in_dontshowlist, - in_showlist, !in_dontshowlist && in_showlist); + ConsoleDebug(WINLIST, "returning: %d %d %d\n", in_dontshowlist, + in_showlist, !in_dontshowlist && in_showlist); - return (!in_dontshowlist && in_showlist); + return (!in_dontshowlist && in_showlist); } -WinData *new_windata (void) +WinData * +new_windata(void) { - WinData *new = (WinData *)safemalloc (sizeof (WinData)); - new->desknum = ULONG_MAX; - new->x = ULONG_MAX; - new->y = ULONG_MAX; - new->geometry_set = 0; - new->app_id = ULONG_MAX; - new->app_id_set = 0; - new->resname = NULL; - new->classname = NULL; - new->iconname = NULL; - new->titlename = NULL; - new->display_string = NULL; - new->manager = NULL; - new->win_prev = new->win_next = NULL; - new->iconified = 0; - new->button = NULL; - new->state = 0; - new->complete = 0; - new->fvwm_flags = 0; + WinData *new = (WinData *)xmalloc(sizeof(WinData)); + new->desknum = ULONG_MAX; + new->x = ULONG_MAX; + new->y = ULONG_MAX; + new->geometry_set = 0; + new->app_id = ULONG_MAX; + new->app_id_set = 0; + new->resname = NULL; + new->classname = NULL; + new->iconname = NULL; + new->titlename = NULL; + new->display_string = NULL; + new->manager = NULL; + new->win_prev = new->win_next = NULL; + new->iconified = 0; + new->button = NULL; + new->state = 0; + new->complete = 0; + new->fvwm_flags = 0; #ifdef MINI_ICONS - new->pic.picture = 0; + new->pic.picture = 0; #endif - return new; + return new; } -void free_windata (WinData *p) +void +free_windata(WinData *p) { - if (globals.select_win == p) { - ConsoleMessage ("Internal error in free_windata\n"); - globals.select_win = NULL; - abort(); - } - - Free (p->resname); - Free (p->classname); - Free (p->iconname); - Free (p); -} + if (globals.select_win == p) { + ConsoleMessage("Internal error in free_windata\n"); + globals.select_win = NULL; + abort(); + } + Free(p->resname); + Free(p->classname); + Free(p->iconname); + Free(p); +} /* This ALWAYS gets called when one of the name strings changes */ -WinManager *figure_win_manager (WinData *win, Uchar name_mask) +WinManager * +figure_win_manager(WinData *win, Uchar name_mask) { - int i; - char *tname = win->titlename; - char *iname = win->iconname; - char *rname = win->resname; - char *cname = win->classname; - WinManager *man; - - assert (tname || iname || rname || cname); - ConsoleDebug (WINLIST, "set_win_manager: %s %s %s %s\n", tname, iname, rname, cname); - - for (i = 0, man = &globals.managers[0]; i < globals.num_managers; - i++, man++) { - if (iconmanager_show (man, tname, iname, rname, cname)) { - if (man != win->manager) { - assert (man->magic == 0x12344321); - } - return man; - } - } - - /* No manager wants this window */ - return NULL; + int i; + char *tname = win->titlename; + char *iname = win->iconname; + char *rname = win->resname; + char *cname = win->classname; + WinManager *man; + + assert(tname || iname || rname || cname); + ConsoleDebug(WINLIST, "set_win_manager: %s %s %s %s\n", tname, iname, + rname, cname); + + for (i = 0, man = &globals.managers[0]; i < globals.num_managers; + i++, man++) { + if (iconmanager_show(man, tname, iname, rname, cname)) { + if (man != win->manager) { + assert(man->magic == 0x12344321); + } + return man; + } + } + + /* No manager wants this window */ + return NULL; } -int check_win_complete (WinData *p) +int +check_win_complete(WinData *p) { - if (p->complete) - return 1; - - ConsoleDebug (WINLIST, "Checking completeness:\n"); - ConsoleDebug (WINLIST, "\ttitlename: %s\n", - (p->titlename ? p->titlename : "No Title name")); - ConsoleDebug (WINLIST, "\ticonname: %s\n", - (p->iconname ? p->iconname : "No Icon name")); - ConsoleDebug (WINLIST, "\tres: %s\n", - (p->resname ? p->resname : "No p->resname")); - ConsoleDebug (WINLIST, "\tclass: %s\n", - (p->classname ? p->classname : "No p->classname")); - ConsoleDebug (WINLIST, "\tdisplaystring: %s\n", - (p->display_string ? p->display_string : - "No p->display_string")); - ConsoleDebug (WINLIST, "\t(x, y): (%ld, %ld)\n", p->x, p->y); - ConsoleDebug (WINLIST, "\tapp_id: 0x%lx %d\n", p->app_id, p->app_id_set); - ConsoleDebug (WINLIST, "\tdesknum: %ld\n", p->desknum); - ConsoleDebug (WINLIST, "\tmanager: 0x%lx\n", (unsigned long)p->manager); - - if (p->geometry_set && - p->resname && - p->classname && - p->iconname && - p->titlename && - p->manager && - p->app_id_set) { - p->complete = 1; - ConsoleDebug (WINLIST, "\tcomplete: 1\n\n"); - return 1; - } - - ConsoleDebug (WINLIST, "\tcomplete: 0\n\n"); - return 0; + int need_resname = 0; + int have_required_names = 0; + + if (p->complete) + return 1; + + if (p->manager) { + if (p->manager->format_depend & RESOURCE_NAME) + need_resname = 1; + else if (stringlist_requires_name( + &p->manager->show, RESOURCE_NAME)) + need_resname = 1; + else if (stringlist_requires_name( + &p->manager->dontshow, RESOURCE_NAME)) + need_resname = 1; + } + + ConsoleDebug(WINLIST, "Checking completeness:\n"); + ConsoleDebug(WINLIST, "\ttitlename: %s\n", + (p->titlename ? p->titlename : "No Title name")); + ConsoleDebug(WINLIST, "\ticonname: %s\n", + (p->iconname ? p->iconname : "No Icon name")); + ConsoleDebug(WINLIST, "\tres: %s\n", + (p->resname ? p->resname : "No p->resname")); + ConsoleDebug(WINLIST, "\tclass: %s\n", + (p->classname ? p->classname : "No p->classname")); + ConsoleDebug(WINLIST, "\tdisplaystring: %s\n", + (p->display_string ? p->display_string : "No p->display_string")); + ConsoleDebug(WINLIST, "\t(x, y): (%ld, %ld)\n", p->x, p->y); + ConsoleDebug(WINLIST, "\tapp_id: 0x%lx %d\n", p->app_id, p->app_id_set); + ConsoleDebug(WINLIST, "\tdesknum: %ld\n", p->desknum); + ConsoleDebug(WINLIST, "\tmanager: 0x%lx\n", (unsigned long)p->manager); + ConsoleDebug(WINLIST, "\tneed_resname: %d\n", need_resname); + + have_required_names = (!need_resname || p->resname) && p->classname && + p->iconname && p->titlename; + + if (p->geometry_set && have_required_names && p->manager && + p->app_id_set) { + p->complete = 1; + ConsoleDebug(WINLIST, "\tcomplete: 1\n\n"); + return 1; + } + + ConsoleDebug(WINLIST, "\tcomplete: 0\n\n"); + return 0; } - -void init_winlists (void) + +void +init_winlists(void) { - int i; - for (i = 0; i < HASHTAB_SIZE; i++) { - hash_tab[i].n = 0; - hash_tab[i].head = NULL; - hash_tab[i].tail = NULL; - } + int i; + for (i = 0; i < HASHTAB_SIZE; i++) { + hash_tab[i].n = 0; + hash_tab[i].head = NULL; + hash_tab[i].tail = NULL; + } } -void delete_win_hashtab (WinData *win) +void +delete_win_hashtab(WinData *win) { - int entry; - WinList *list; - - entry = win->app_id & 0xff; - list = &hash_tab[entry]; - - if (win->win_prev) - win->win_prev->win_next = win->win_next; - else - list->head = win->win_next; - if (win->win_next) - win->win_next->win_prev = win->win_prev; - else - list->tail = win->win_prev; - list->n--; -} - -void insert_win_hashtab (WinData *win) + int entry; + WinList *list; + + entry = win->app_id & 0xff; + list = &hash_tab[entry]; + + if (win->win_prev) + win->win_prev->win_next = win->win_next; + else + list->head = win->win_next; + if (win->win_next) + win->win_next->win_prev = win->win_prev; + else + list->tail = win->win_prev; + list->n--; +} + +void +insert_win_hashtab(WinData *win) { - int entry; - WinList *list; - WinData *p; - - entry = win->app_id & 0xff; - list = &hash_tab[entry]; - - for (p = list->head; p && win->app_id > p->app_id; - p = p->win_next); - - if (p) { - /* insert win before p */ - win->win_next = p; - win->win_prev = p->win_prev; - if (p->win_prev) - p->win_prev->win_next = win; - else - list->head = win; - p->win_prev = win; - } - else { - /* put win at end of list */ - win->win_next = NULL; - win->win_prev = list->tail; - if (list->tail) - list->tail->win_next = win; - else - list->head = win; - list->tail = win; - } - list->n++; + int entry; + WinList *list; + WinData *p; + + entry = win->app_id & 0xff; + list = &hash_tab[entry]; + + for (p = list->head; p && win->app_id > p->app_id; p = p->win_next) + ; + + if (p) { + /* insert win before p */ + win->win_next = p; + win->win_prev = p->win_prev; + if (p->win_prev) + p->win_prev->win_next = win; + else + list->head = win; + p->win_prev = win; + } else { + /* put win at end of list */ + win->win_next = NULL; + win->win_prev = list->tail; + if (list->tail) + list->tail->win_next = win; + else + list->head = win; + list->tail = win; + } + list->n++; } -WinData *find_win_hashtab (Ulong id) +WinData * +find_win_hashtab(Ulong id) { - WinList *list; - int entry = id & 0xff; - WinData *p; + WinList *list; + int entry = id & 0xff; + WinData *p; - list = &hash_tab[entry]; + list = &hash_tab[entry]; - for (p = list->head; p && p->app_id != id; p = p->win_next); + for (p = list->head; p && p->app_id != id; p = p->win_next) + ; - return p; + return p; } -void walk_hashtab (void (*func)(void *)) +void +walk_hashtab(void (*func)(void *)) { - int i; - WinData *p; + int i; + WinData *p; - for (i = 0; i < HASHTAB_SIZE; i++) { - for (p = hash_tab[i].head; p; p = p->win_next) - func (p); - } + for (i = 0; i < HASHTAB_SIZE; i++) { + for (p = hash_tab[i].head; p; p = p->win_next) + func(p); + } } -int accumulate_walk_hashtab (int (*func)(void *)) +int +accumulate_walk_hashtab(int (*func)(void *)) { - int i, ret = 0; - WinData *p; + int i, ret = 0; + WinData *p; - for (i = 0; i < HASHTAB_SIZE; i++) { - for (p = hash_tab[i].head; p; p = p->win_next) - ret += func (p); - } + for (i = 0; i < HASHTAB_SIZE; i++) { + for (p = hash_tab[i].head; p; p = p->win_next) + ret += func(p); + } - return ret; + return ret; } Index: fvwm/modules/FvwmIconMan/x.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/x.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/x.c --- fvwm/modules/FvwmIconMan/x.c +++ fvwm/modules/FvwmIconMan/x.c @@ -1,13 +1,16 @@ -#include "config.h" +#include "x.h" + #include "FvwmIconMan.h" +#include "config.h" #include "readconfig.h" -#include "x.h" #include "xmanager.h" static char const rcsid[] = - "$Id: x.c,v 1.1.1.1 2006/11/26 10:53:50 matthieu Exp $"; + "$Id: x.c,v 1.1.1.1 2006/11/26 10:53:50 matthieu Exp $"; -#define GRAB_EVENTS (ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|EnterWindowMask|LeaveWindowMask) +#define GRAB_EVENTS \ + (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | \ + EnterWindowMask | LeaveWindowMask) #ifdef SHAPE static int shapeEventBase, shapeErrorBase; @@ -18,130 +21,139 @@ Window theRoot; int theDepth, theScreen; static enum { - NOT_GRABBED = 0, - NEED_TO_GRAB = 1, - HAVE_GRABBED = 2 + NOT_GRABBED = 0, + NEED_TO_GRAB = 1, + HAVE_GRABBED = 2 } grab_state = NOT_GRABBED; -static void reparentnotify_event (WinManager *man, XEvent *ev); +static void reparentnotify_event(WinManager *man, XEvent *ev); -static void grab_pointer (WinManager *man) +static void +grab_pointer(WinManager *man) { - /* This should only be called after we get our EXPOSE event */ - if (grab_state == NEED_TO_GRAB) { - if (XGrabPointer (theDisplay, man->theWindow, True, GRAB_EVENTS, - GrabModeAsync, GrabModeAsync, None, - None, CurrentTime) != GrabSuccess) { - ConsoleMessage ("Couldn't grab pointer\n"); - ShutMeDown (0); - } - grab_state = HAVE_GRABBED; - } + /* This should only be called after we get our EXPOSE event */ + if (grab_state == NEED_TO_GRAB) { + if (XGrabPointer(theDisplay, man->theWindow, True, GRAB_EVENTS, + GrabModeAsync, GrabModeAsync, None, None, + CurrentTime) != GrabSuccess) { + ConsoleMessage("Couldn't grab pointer\n"); + ShutMeDown(0); + } + grab_state = HAVE_GRABBED; + } } -static int lookup_color (char *name, Pixel *ans) +static int +lookup_color(char *name, Pixel *ans) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(theDisplay, theRoot, &attributes); - color.pixel = 0; - if (!XParseColor (theDisplay, attributes.colormap, name, &color)) { - ConsoleDebug(X11, "Could not parse color '%s'\n", name); - return 0; - } - else if(!XAllocColor (theDisplay, attributes.colormap, &color)) { - ConsoleDebug(X11, "Could not allocate color '%s'\n", name); - return 0; - } - *ans = color.pixel; - return 1; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(theDisplay, theRoot, &attributes); + color.pixel = 0; + if (!XParseColor(theDisplay, attributes.colormap, name, &color)) { + ConsoleDebug(X11, "Could not parse color '%s'\n", name); + return 0; + } else if (!XAllocColor(theDisplay, attributes.colormap, &color)) { + ConsoleDebug(X11, "Could not allocate color '%s'\n", name); + return 0; + } + *ans = color.pixel; + return 1; } - -WinManager *find_windows_manager (Window win) +WinManager * +find_windows_manager(Window win) { - int i; - - for (i = 0; i < globals.num_managers; i++) { - if (globals.managers[i].theWindow == win) - return &globals.managers[i]; - } - -/* ConsoleMessage ("error in find_windows_manager:\n"); - ConsoleMessage ("Window: %x\n", win); - for (i = 0; i < globals.num_managers; i++) { - ConsoleMessage ("manager: %d %x\n", i, globals.managers[i].theWindow); - } -*/ - return NULL; + int i; + + for (i = 0; i < globals.num_managers; i++) { + if (globals.managers[i].theWindow == win) + return &globals.managers[i]; + } + + /* ConsoleMessage ("error in find_windows_manager:\n"); + ConsoleMessage ("Window: %x\n", win); + for (i = 0; i < globals.num_managers; i++) { + ConsoleMessage ("manager: %d %x\n", i, globals.managers[i].theWindow); + } + */ + return NULL; } -static void handle_buttonevent (XEvent *theEvent, WinManager *man) +static void +handle_buttonevent(XEvent *theEvent, WinManager *man) { - Button *b; - WinData *win; - unsigned int modifier; - Binding *MouseEntry; - - b = xy_to_button (man, theEvent->xbutton.x, theEvent->xbutton.y); - if (b && theEvent->xbutton.button >= 1 && theEvent->xbutton.button <= 3) { - win = b->drawn_state.win; - if (win != NULL) { - ConsoleDebug (X11, "Found the window:\n"); - ConsoleDebug (X11, "\tid: %ld\n", win->app_id); - ConsoleDebug (X11, "\tdesknum: %ld\n", win->desknum); - ConsoleDebug (X11, "\tx, y: %ld %ld\n", win->x, win->y); - ConsoleDebug (X11, "\ticon: %p\n", win->iconname); - ConsoleDebug (X11, "\ticonified: %d\n", win->iconified); - ConsoleDebug (X11, "\tcomplete: %d\n", win->complete); - - modifier = (theEvent->xbutton.state & MODS_USED); - /* need to search for an appropriate mouse binding */ - for (MouseEntry = man->bindings[MOUSE]; MouseEntry != NULL; - MouseEntry= MouseEntry->NextBinding) { - if(((MouseEntry->Button_Key == theEvent->xbutton.button)|| - (MouseEntry->Button_Key == 0))&& - ((MouseEntry->Modifier == AnyModifier)|| - (MouseEntry->Modifier == (modifier& (~LockMask))))) - { - Function *ftype = MouseEntry->Function; - ConsoleDebug (X11, "\tgot a mouse binding\n"); - if (ftype && ftype->func) { - run_function_list (ftype); - draw_managers(); - } - break; + Button *b; + WinData *win; + unsigned int modifier; + Binding *MouseEntry; + + b = xy_to_button(man, theEvent->xbutton.x, theEvent->xbutton.y); + if (b && theEvent->xbutton.button >= 1 && + theEvent->xbutton.button <= 3) { + win = b->drawn_state.win; + if (win != NULL) { + ConsoleDebug(X11, "Found the window:\n"); + ConsoleDebug(X11, "\tid: %ld\n", win->app_id); + ConsoleDebug(X11, "\tdesknum: %ld\n", win->desknum); + ConsoleDebug( + X11, "\tx, y: %ld %ld\n", win->x, win->y); + ConsoleDebug(X11, "\ticon: %p\n", win->iconname); + ConsoleDebug(X11, "\ticonified: %d\n", win->iconified); + ConsoleDebug(X11, "\tcomplete: %d\n", win->complete); + + modifier = (theEvent->xbutton.state & MODS_USED); + /* need to search for an appropriate mouse binding */ + for (MouseEntry = man->bindings[MOUSE]; + MouseEntry != NULL; + MouseEntry = MouseEntry->NextBinding) { + if (((MouseEntry->Button_Key == + theEvent->xbutton.button) || + (MouseEntry->Button_Key == 0)) && + ((MouseEntry->Modifier == AnyModifier) || + (MouseEntry->Modifier == + (modifier & (~LockMask))))) { + Function *ftype = MouseEntry->Function; + ConsoleDebug( + X11, "\tgot a mouse binding\n"); + if (ftype && ftype->func) { + run_function_list(ftype); + draw_managers(); + } + break; + } + } + } } - } - } - } } -Window find_frame_window (Window win, int *off_x, int *off_y) +Window +find_frame_window(Window win, int *off_x, int *off_y) { - Window root, parent, *junkw; - int junki; - XWindowAttributes attr; - - ConsoleDebug (X11, "In find_frame_window: 0x%x\n", (unsigned int)win); - - while (1) { - XQueryTree (theDisplay, win, &root, &parent, &junkw, &junki); - if (junkw) - XFree (junkw); - if (parent == root) - break; - XGetWindowAttributes (theDisplay, win, &attr); - ConsoleDebug (X11, "Adding (%d, %d) += (%d, %d)\n", - *off_x, *off_y, attr.x + attr.border_width, - attr.y + attr.border_width); - *off_x += attr.x + attr.border_width; - *off_y += attr.y + attr.border_width; - win = parent; - } - - return win; + Window root, parent, *junkw; + int junki; + XWindowAttributes attr; + + ConsoleDebug(X11, "In find_frame_window: 0x%x\n", (unsigned int)win); + + while (1) { + junkw = NULL; + if (XQueryTree(theDisplay, win, &root, &parent, &junkw, + &junki) && junkw) + XFree(junkw); + if (parent == root) + break; + XGetWindowAttributes(theDisplay, win, &attr); + ConsoleDebug(X11, "Adding (%d, %d) += (%d, %d)\n", *off_x, + *off_y, attr.x + attr.border_width, + attr.y + attr.border_width); + *off_x += attr.x + attr.border_width; + *off_y += attr.y + attr.border_width; + win = parent; + } + + return win; } /***************************************************************************/ @@ -149,665 +161,616 @@ Window find_frame_window (Window win, int *off_x, int *off_y) /* everything which has its own routine can be processed recursively */ /***************************************************************************/ -static void reparentnotify_event (WinManager *man, XEvent *ev) +static void +reparentnotify_event(WinManager *man, XEvent *ev) { - ConsoleDebug (X11, "XEVENT: ReparentNotify\n"); -#if 0 - ConsoleMessage ("seen %d expected %d\n", num_reparents_seen, - num_reparents_expected); - man->off_x = ev->xreparent.x; - man->off_y = ev->xreparent.y; - ConsoleDebug (X11, "reparent: off = (%d, %d)\n",man->off_x, man->off_y); - man->theFrame = find_frame_window (ev->xany.window, - &man->off_x, &man->off_y); - ConsoleMessage ("\twin = 0x%x, frame = 0x%x\n", man->theWindow, - man->theFrame); -#endif - if (man->can_draw == 0) { - man->can_draw = 1; - force_manager_redraw (man); - } + ConsoleDebug(X11, "XEVENT: ReparentNotify\n"); + if (man->can_draw == 0) { + man->can_draw = 1; + force_manager_redraw(man); + } } -void xevent_loop (void) +void +xevent_loop(void) { - XEvent theEvent; - unsigned int modifier; - Binding *key; - Button *b; - static int flag = 0; - WinManager *man; - - if (flag == 0) { - flag = 1; - ConsoleDebug (X11, "A virgin event loop\n"); - } - while (XPending (theDisplay)) { - XNextEvent (theDisplay, &theEvent); - if (theEvent.type == MappingNotify) { - ConsoleDebug (X11, "XEVENT: MappingNotify\n"); - continue; - } - - man = find_windows_manager (theEvent.xany.window); - if (!man) { - ConsoleDebug (X11, "Event doesn't belong to a manager\n"); - continue; - } - - switch (theEvent.type) { - case ReparentNotify: - reparentnotify_event (man, &theEvent); - break; - - case KeyPress: - ConsoleDebug (X11, "XEVENT: KeyPress\n"); - /* 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. */ - theEvent.xkey.keycode = - XKeysymToKeycode (theDisplay, - XKeycodeToKeysym(theDisplay, - theEvent.xkey.keycode,0)); - modifier = (theEvent.xkey.state & MODS_USED); - ConsoleDebug (X11, "\tKeyPress: %d\n", theEvent.xkey.keycode); - - for (key = man->bindings[KEYPRESS]; key != NULL; key = key->NextBinding) - { - if ((key->Button_Key == theEvent.xkey.keycode) && - ((key->Modifier == (modifier&(~LockMask)))|| - (key->Modifier == AnyModifier))) - { - Function *ftype = key->Function; - if (ftype && ftype->func) { - run_function_list (ftype); - draw_managers(); - } - break; - } - } - break; - - case Expose: - ConsoleDebug (X11, "XEVENT: Expose\n"); - if (theEvent.xexpose.count == 0) { - man_exposed (man, &theEvent); - draw_manager (man); - if (globals.transient) { - grab_pointer (man); - } - } - break; - - case ButtonPress: - ConsoleDebug (X11, "XEVENT: ButtonPress\n"); - if (!globals.transient) - handle_buttonevent (&theEvent, man); - break; - - case ButtonRelease: - ConsoleDebug (X11, "XEVENT: ButtonRelease\n"); - if (globals.transient) { - handle_buttonevent (&theEvent, man); - ShutMeDown (0); - } - break; - - case EnterNotify: - ConsoleDebug (X11, "XEVENT: EnterNotify\n"); - man->cursor_in_window = 1; - b = xy_to_button (man, theEvent.xcrossing.x, theEvent.xcrossing.y); - move_highlight (man, b); - run_binding (man, SELECT); - draw_managers(); - break; - - case LeaveNotify: - ConsoleDebug (X11, "XEVENT: LeaveNotify\n"); - move_highlight (man, NULL); - break; - - case ConfigureNotify: - ConsoleDebug (X11, "XEVENT: Configure Notify: %d %d %d %d\n", - theEvent.xconfigure.x, theEvent.xconfigure.y, - theEvent.xconfigure.width, theEvent.xconfigure.height); - ConsoleDebug (X11, "\tcurrent geometry: %d %d %d %d\n", - man->geometry.x, man->geometry.y, - man->geometry.width, man->geometry.height); - ConsoleDebug (X11, "\tborderwidth = %d\n", - theEvent.xconfigure.border_width); - ConsoleDebug (X11, "\tsendevent = %d\n", theEvent.xconfigure.send_event); -#if 0 - set_manager_width (man, theEvent.xconfigure.width); - ConsoleDebug (X11, "\tboxwidth = %d\n", man->geometry.boxwidth); - draw_manager (man); - - /* pointer may not be in the same box as before */ - if (XQueryPointer (theDisplay, man->theWindow, &root, &child, &glob_x, - &glob_y, - &x, &y, &mask)) { - b = xy_to_button (man, x, y); - if (b != man->select_button) { - move_highlight (man, b); - run_binding (man, SELECT); - draw_managers(); + XEvent theEvent; + unsigned int modifier; + Binding *key; + Button *b; + static int flag = 0; + WinManager *man; + + if (flag == 0) { + flag = 1; + ConsoleDebug(X11, "A virgin event loop\n"); } - } - else { - if (man->select_button != NULL) - move_highlight (NULL, NULL); - } -#endif - break; - - case MotionNotify: - /* ConsoleDebug (X11, "XEVENT: MotionNotify\n"); */ - b = xy_to_button (man, theEvent.xmotion.x, theEvent.xmotion.y); - if (b != man->select_button) { - ConsoleDebug (X11, "\tmoving select\n"); - move_highlight (man, b); - run_binding (man, SELECT); - draw_managers(); - } - break; - - case MapNotify: - ConsoleDebug (X11, "XEVENT: MapNotify\n"); - force_manager_redraw (man); - break; - - case UnmapNotify: - ConsoleDebug (X11, "XEVENT: UnmapNotify\n"); - break; - - case DestroyNotify: - ConsoleDebug(X11, "XEVENT: DestroyNotify\n"); - DeadPipe(0); - break; - - default: + while (XPending(theDisplay)) { + XNextEvent(theDisplay, &theEvent); + if (theEvent.type == MappingNotify) { + ConsoleDebug(X11, "XEVENT: MappingNotify\n"); + continue; + } + + man = find_windows_manager(theEvent.xany.window); + if (!man) { + ConsoleDebug( + X11, "Event doesn't belong to a manager\n"); + continue; + } + + switch (theEvent.type) { + case ReparentNotify: + reparentnotify_event(man, &theEvent); + break; + + case KeyPress: + ConsoleDebug(X11, "XEVENT: KeyPress\n"); + /* 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. */ + { + KeySym *mapping; + int width; + + mapping = XGetKeyboardMapping(theDisplay, + theEvent.xkey.keycode, 1, &width); + if (mapping != NULL) { + KeySym primary = + (width > 0) ? mapping[0] : NoSymbol; + KeyCode canonical = + (primary != NoSymbol) ? + XKeysymToKeycode( + theDisplay, primary) : + 0; + if (canonical != 0) + theEvent.xkey.keycode = + canonical; + XFree(mapping); + } + } + modifier = (theEvent.xkey.state & MODS_USED); + ConsoleDebug( + X11, "\tKeyPress: %d\n", theEvent.xkey.keycode); + + for (key = man->bindings[KEYPRESS]; key != NULL; + key = key->NextBinding) { + if ((key->Button_Key == + theEvent.xkey.keycode) && + ((key->Modifier == + (modifier & (~LockMask))) || + (key->Modifier == AnyModifier))) { + Function *ftype = key->Function; + if (ftype && ftype->func) { + run_function_list(ftype); + draw_managers(); + } + break; + } + } + break; + + case Expose: + ConsoleDebug(X11, "XEVENT: Expose\n"); + if (theEvent.xexpose.count == 0) { + man_exposed(man, &theEvent); + draw_manager(man); + if (globals.transient) { + grab_pointer(man); + } + } + break; + + case ButtonPress: + ConsoleDebug(X11, "XEVENT: ButtonPress\n"); + if (!globals.transient) + handle_buttonevent(&theEvent, man); + break; + + case ButtonRelease: + ConsoleDebug(X11, "XEVENT: ButtonRelease\n"); + if (globals.transient) { + handle_buttonevent(&theEvent, man); + ShutMeDown(0); + } + break; + + case EnterNotify: + ConsoleDebug(X11, "XEVENT: EnterNotify\n"); + man->cursor_in_window = 1; + b = xy_to_button( + man, theEvent.xcrossing.x, theEvent.xcrossing.y); + move_highlight(man, b); + run_binding(man, SELECT); + draw_managers(); + break; + + case LeaveNotify: + ConsoleDebug(X11, "XEVENT: LeaveNotify\n"); + move_highlight(man, NULL); + break; + + case ConfigureNotify: + ConsoleDebug(X11, + "XEVENT: Configure Notify: %d %d %d %d\n", + theEvent.xconfigure.x, theEvent.xconfigure.y, + theEvent.xconfigure.width, + theEvent.xconfigure.height); + ConsoleDebug(X11, "\tcurrent geometry: %d %d %d %d\n", + man->geometry.x, man->geometry.y, + man->geometry.width, man->geometry.height); + ConsoleDebug(X11, "\tborderwidth = %d\n", + theEvent.xconfigure.border_width); + ConsoleDebug(X11, "\tsendevent = %d\n", + theEvent.xconfigure.send_event); + break; + + case MotionNotify: + /* ConsoleDebug (X11, "XEVENT: MotionNotify\n"); */ + b = xy_to_button( + man, theEvent.xmotion.x, theEvent.xmotion.y); + if (b != man->select_button) { + ConsoleDebug(X11, "\tmoving select\n"); + move_highlight(man, b); + run_binding(man, SELECT); + draw_managers(); + } + break; + + case MapNotify: + ConsoleDebug(X11, "XEVENT: MapNotify\n"); + force_manager_redraw(man); + break; + + case UnmapNotify: + ConsoleDebug(X11, "XEVENT: UnmapNotify\n"); + break; + + case DestroyNotify: + ConsoleDebug(X11, "XEVENT: DestroyNotify\n"); + DeadPipe(0); + break; + + default: #ifdef SHAPE - if (theEvent.type == shapeEventBase + ShapeNotify) { - XShapeEvent *xev = (XShapeEvent *)&theEvent; - ConsoleDebug (X11, "XEVENT: ShapeNotify\n"); - ConsoleDebug (X11, "\tx, y, w, h = %d, %d, %d, %d\n", - xev->x, xev->y, xev->width, xev->height); - break; - } + if (theEvent.type == shapeEventBase + ShapeNotify) { + XShapeEvent *xev = (XShapeEvent *)&theEvent; + ConsoleDebug(X11, "XEVENT: ShapeNotify\n"); + ConsoleDebug(X11, + "\tx, y, w, h = %d, %d, %d, %d\n", xev->x, + xev->y, xev->width, xev->height); + break; + } #endif - ConsoleDebug (X11, "XEVENT: unknown\n"); - break; - } - } - check_managers_consistency(); - XFlush (theDisplay); + ConsoleDebug(X11, "XEVENT: unknown\n"); + break; + } + } + check_managers_consistency(); + XFlush(theDisplay); } -static void set_window_properties (Window win, char *name, char *icon, - XSizeHints *sizehints) +static void +set_window_properties(Window win, char *name, char *icon, XSizeHints *sizehints) { - XTextProperty win_name; - XTextProperty win_icon; - XClassHint class; - XWMHints wmhints = {0}; - - wmhints.initial_state = NormalState; - wmhints.flags = StateHint; + XTextProperty win_name; + XTextProperty win_icon; + XClassHint class; + XWMHints wmhints = {0}; - if (XStringListToTextProperty (&name, 1, &win_name) == 0) { - ConsoleMessage ("%s: cannot allocate window name.\n",Module); - return; - } - if (XStringListToTextProperty (&icon, 1, &win_icon) == 0) { - ConsoleMessage ("%s: cannot allocate window icon.\n",Module); - return; - } + wmhints.initial_state = NormalState; + wmhints.flags = StateHint; - class.res_name = Module + 1; - class.res_class = "FvwmModule"; + if (XStringListToTextProperty(&name, 1, &win_name) == 0) { + ConsoleMessage("%s: cannot allocate window name.\n", Module); + return; + } + if (XStringListToTextProperty(&icon, 1, &win_icon) == 0) { + ConsoleMessage("%s: cannot allocate window icon.\n", Module); + return; + } + class.res_name = Module + 1; + class.res_class = "FvwmModule"; - XSetWMProperties (theDisplay, win, &win_name, &win_icon, NULL, 0, - sizehints, &wmhints, &class); + XSetWMProperties(theDisplay, win, &win_name, &win_icon, NULL, 0, + sizehints, &wmhints, &class); - XFree (win_name.value); - XFree (win_icon.value); + XFree(win_name.value); + XFree(win_icon.value); } -static int load_default_context_fore (WinManager *man, int i) +static int +load_default_context_fore(WinManager *man, int i) { - int j = 0; + int j = 0; - if (theDepth > 2) - j = 1; + if (theDepth > 2) + j = 1; - ConsoleDebug (X11, "Loading: %s\n", contextDefaults[i].backcolor[j]); + ConsoleDebug(X11, "Loading: %s\n", contextDefaults[i].backcolor[j]); - return lookup_color (contextDefaults[i].forecolor[j], &man->forecolor[i]); + return lookup_color( + contextDefaults[i].forecolor[j], &man->forecolor[i]); } -static int load_default_context_back (WinManager *man, int i) +static int +load_default_context_back(WinManager *man, int i) { - int j = 0; + int j = 0; - if (theDepth > 2) - j = 1; + if (theDepth > 2) + j = 1; - ConsoleDebug (X11, "Loading: %s\n", contextDefaults[i].backcolor[j]); + ConsoleDebug(X11, "Loading: %s\n", contextDefaults[i].backcolor[j]); - return lookup_color (contextDefaults[i].backcolor[j], &man->backcolor[i]); + return lookup_color( + contextDefaults[i].backcolor[j], &man->backcolor[i]); } -void map_manager (WinManager *man) +void +map_manager(WinManager *man) { - if (man->window_mapped == 0 && man->geometry.height > 0) { - XMapWindow (theDisplay, man->theWindow); - set_manager_window_mapping (man, 1); - XFlush (theDisplay); - if (globals.transient) { - /* wait for an expose event to actually do the grab */ - grab_state = NEED_TO_GRAB; - } - } + if (man->window_mapped == 0 && man->geometry.height > 0) { + XMapWindow(theDisplay, man->theWindow); + set_manager_window_mapping(man, 1); + XFlush(theDisplay); + if (globals.transient) { + /* wait for an expose event to actually do the grab */ + grab_state = NEED_TO_GRAB; + } + } } -void unmap_manager (WinManager *man) +void +unmap_manager(WinManager *man) { - if (man->window_mapped == 1) { - XUnmapWindow (theDisplay, man->theWindow); - set_manager_window_mapping (man, 0); - XFlush (theDisplay); - } + if (man->window_mapped == 1) { + XUnmapWindow(theDisplay, man->theWindow); + set_manager_window_mapping(man, 0); + XFlush(theDisplay); + } } -#if 0 -void read_all_reparent_events (WinManager *man, int block) +void +X_init_manager(int man_id) { - XEvent evs[2]; - int i = 0, got_one = 0, the_event; - - /* We're going to be junking ConfigureNotify events, but that's ok, - since this is only going to be called from resize_manager() */ - /* This shouldn't slow things down terribly, since we'd just have to read - these events anyway */ - - assert (man->can_draw); - - if (block) { - while (1) { - XWindowEvent (theDisplay, man->theWindow, StructureNotifyMask, &evs[0]); - if (evs[0].type == ReparentNotify) { - the_event = 0; - got_one = 1; - break; - } - } - } - else { - while (XCheckWindowEvent (theDisplay, man->theWindow, StructureNotifyMask, - &evs[i])) { - if (evs[i].type == ReparentNotify) { - got_one = 1; - the_event = i; - i ^= 1; - } - } - } - if (got_one) { - reparentnotify_event (man, &evs[the_event]); - } -} -#endif + WinManager *man; + int width, height; + int i, x, y, geometry_mask; + ConsoleDebug(X11, "In X_init_manager\n"); -void X_init_manager (int man_id) -{ - WinManager *man; - int width, height; - int i, x, y, geometry_mask; - ConsoleDebug (X11, "In X_init_manager\n"); - - man = &globals.managers[man_id]; - - man->geometry.cols = DEFAULT_NUM_COLS; - man->geometry.rows = DEFAULT_NUM_ROWS; - man->geometry.x = 0; - man->geometry.y = 0; - man->gravity = NorthWestGravity; - - man->select_button = NULL; - man->cursor_in_window = 0; - man->sizehints_flags = 0; - - ConsoleDebug (X11, "boxwidth = %d\n", man->geometry.boxwidth); - - if (man->fontname) { - man->ButtonFont = XLoadQueryFont (theDisplay, man->fontname); - if (!man->ButtonFont) { - if (!(man->ButtonFont = XLoadQueryFont (theDisplay, FONT_STRING))) { - ConsoleMessage ("Can't get font\n"); - ShutMeDown (1); - } - } - } - else { - if (!(man->ButtonFont = XLoadQueryFont (theDisplay, FONT_STRING))) { - ConsoleMessage ("Can't get font\n"); - ShutMeDown (1); - } - } - - for ( i = 0; i < NUM_CONTEXTS; i++ ) { - if (man->backColorName[i]) { - if (!lookup_color (man->backColorName[i], &man->backcolor[i])) { - if (!load_default_context_back (man, i)) { - ConsoleMessage ("Can't load %s background color\n", - contextDefaults[i].name); - } - } - } - else if (!load_default_context_back (man, i)) { - ConsoleMessage ("Can't load %s background color\n", - contextDefaults[i].name); - } - - if (man->foreColorName[i]) { - if (!lookup_color (man->foreColorName[i], &man->forecolor[i])) { - if (!load_default_context_fore (man, i)) { - ConsoleMessage ("Can't load %s foreground color\n", - contextDefaults[i].name); - } - } - } - else if (!load_default_context_fore (man, i)) { - ConsoleMessage ("Can't load %s foreground color\n", - contextDefaults[i].name); - } - - if (theDepth > 2) { - man->shadowcolor[i] = GetShadow(man->backcolor[i]); - man->hicolor[i] = GetHilite(man->backcolor[i]); -#if 0 - /* thing about message id bg vs fg */ - if (!lookup_shadow_color (man->backcolor[i], &man->shadowcolor[i])) { - ConsoleMessage ("Can't load %s shadow color\n", - contextDefaults[i].name); - } - if (!lookup_hilite_color (man->backcolor[i], &man->hicolor[i])) { - ConsoleMessage ("Can't load %s hilite color\n", - contextDefaults[i].name); - } -#endif - } - } - - man->fontheight = man->ButtonFont->ascent + - man->ButtonFont->descent; - - /* silly hack to guess the minimum char width of the font - doesn't have to be perfect. */ - - man->fontwidth = XTextWidth (man->ButtonFont, ".", 1); - - /* First: get button geometry - Second: get geometry from geometry string - Third: determine the final width and height - Fourth: determine final x, y coords */ - - man->geometry.boxwidth = DEFAULT_BUTTON_WIDTH; - man->geometry.boxheight = man->fontheight + 4;; - man->geometry.dir = 0; - - geometry_mask = 0; - - if (man->button_geometry_str) { - int val; - val = XParseGeometry (man->button_geometry_str, &x, &y, &width, &height); - ConsoleDebug (X11, "button x, y, w, h = %d %d %d %d\n", x, y, width, - height); - if (val & WidthValue) - man->geometry.boxwidth = width; - if (val & HeightValue) - man->geometry.boxheight = max (man->geometry.boxheight, height); - } - if (man->geometry_str) { - geometry_mask = XParseGeometry (man->geometry_str, &man->geometry.x, - &man->geometry.y, &man->geometry.cols, - &man->geometry.rows); - - if ((geometry_mask & XValue) || (geometry_mask & YValue)) { - man->sizehints_flags |= USPosition; - if (geometry_mask & XNegative) - man->geometry.dir |= GROW_LEFT; - else - man->geometry.dir |= GROW_RIGHT; - if (geometry_mask & YNegative) - man->geometry.dir |= GROW_UP; - else - man->geometry.dir |= GROW_DOWN; - } - } - - if (man->geometry.rows == 0) { - if (man->geometry.cols == 0) { - ConsoleMessage ("You specified a 0x0 window\n"); - ShutMeDown (0); - } - else { - man->geometry.dir |= GROW_VERT; - } - man->geometry.rows = 1; - } - else { - if (man->geometry.cols == 0) { - man->geometry.dir |= GROW_HORIZ; - man->geometry.cols = 1; - } - else { - man->geometry.dir |= GROW_HORIZ | GROW_FIXED; - } - } - - man->geometry.width = man->geometry.cols * man->geometry.boxwidth; - man->geometry.height = man->geometry.rows * man->geometry.boxheight; - - if ((geometry_mask & XValue) && (geometry_mask & XNegative)) - man->geometry.x += globals.screenx - man->geometry.width; - if ((geometry_mask & YValue) && (geometry_mask & YNegative)) - man->geometry.y += globals.screeny - man->geometry.height; - - if (globals.transient) { - Window dummyroot, dummychild; - int junk; - - XQueryPointer(theDisplay, theRoot, &dummyroot, &dummychild, - &man->geometry.x, - &man->geometry.y, &junk, &junk, &junk); - man->geometry.dir |= GROW_DOWN | GROW_RIGHT; - man->sizehints_flags |= USPosition; - } - - if (man->sizehints_flags & USPosition) { - if (man->geometry.dir & GROW_DOWN) { - if (man->geometry.dir & GROW_RIGHT) + man = &globals.managers[man_id]; + + man->geometry.cols = DEFAULT_NUM_COLS; + man->geometry.rows = DEFAULT_NUM_ROWS; + man->geometry.x = 0; + man->geometry.y = 0; man->gravity = NorthWestGravity; - else if (man->geometry.dir & GROW_LEFT) - man->gravity = NorthEastGravity; - else - ConsoleMessage ("Internal error in X_init_manager\n"); - } - else if (man->geometry.dir & GROW_UP) { - if (man->geometry.dir & GROW_RIGHT) - man->gravity = SouthWestGravity; - else if (man->geometry.dir & GROW_LEFT) - man->gravity = SouthEastGravity; - else - ConsoleMessage ("Internal error in X_init_manager\n"); - } - else { - ConsoleMessage ("Internal error in X_init_manager\n"); - } - } - else { - man->geometry.dir |= GROW_DOWN | GROW_RIGHT; - man->gravity = NorthWestGravity; - } + + man->select_button = NULL; + man->cursor_in_window = 0; + man->sizehints_flags = 0; + + ConsoleDebug(X11, "boxwidth = %d\n", man->geometry.boxwidth); + + if (man->fontname) { + man->ButtonFont = XLoadQueryFont(theDisplay, man->fontname); + if (!man->ButtonFont) { + if (!(man->ButtonFont = + XLoadQueryFont(theDisplay, FONT_STRING))) { + ConsoleMessage("Can't get font\n"); + ShutMeDown(1); + } + } + } else { + if (!(man->ButtonFont = + XLoadQueryFont(theDisplay, FONT_STRING))) { + ConsoleMessage("Can't get font\n"); + ShutMeDown(1); + } + } + + for (i = 0; i < NUM_CONTEXTS; i++) { + if (man->backColorName[i]) { + if (!lookup_color( + man->backColorName[i], &man->backcolor[i])) { + if (!load_default_context_back(man, i)) { + ConsoleMessage( + "Can't load %s background color\n", + contextDefaults[i].name); + } + } + } else if (!load_default_context_back(man, i)) { + ConsoleMessage("Can't load %s background color\n", + contextDefaults[i].name); + } + + if (man->foreColorName[i]) { + if (!lookup_color( + man->foreColorName[i], &man->forecolor[i])) { + if (!load_default_context_fore(man, i)) { + ConsoleMessage( + "Can't load %s foreground color\n", + contextDefaults[i].name); + } + } + } else if (!load_default_context_fore(man, i)) { + ConsoleMessage("Can't load %s foreground color\n", + contextDefaults[i].name); + } + + if (theDepth > 2) { + man->shadowcolor[i] = GetShadow(man->backcolor[i]); + man->hicolor[i] = GetHilite(man->backcolor[i]); + } + } + + man->fontheight = man->ButtonFont->ascent + man->ButtonFont->descent; + + /* Silly hack to guess the minimum char width of the font + doesn't have to be perfect. */ + + man->fontwidth = XTextWidth(man->ButtonFont, ".", 1); + + /* First: get button geometry + Second: get geometry from geometry string + Third: determine the final width and height + Fourth: determine final x, y coords */ + + man->geometry.boxwidth = DEFAULT_BUTTON_WIDTH; + man->geometry.boxheight = man->fontheight + 4; + ; + man->geometry.dir = 0; + + geometry_mask = 0; + + if (man->button_geometry_str) { + int val; + val = XParseGeometry( + man->button_geometry_str, &x, &y, &width, &height); + ConsoleDebug(X11, "button x, y, w, h = %d %d %d %d\n", x, y, + width, height); + if (val & WidthValue) + man->geometry.boxwidth = width; + if (val & HeightValue) + man->geometry.boxheight = + max(man->geometry.boxheight, height); + } + if (man->geometry_str) { + geometry_mask = XParseGeometry(man->geometry_str, + &man->geometry.x, &man->geometry.y, &man->geometry.cols, + &man->geometry.rows); + + if ((geometry_mask & XValue) || (geometry_mask & YValue)) { + man->sizehints_flags |= USPosition; + if (geometry_mask & XNegative) + man->geometry.dir |= GROW_LEFT; + else + man->geometry.dir |= GROW_RIGHT; + if (geometry_mask & YNegative) + man->geometry.dir |= GROW_UP; + else + man->geometry.dir |= GROW_DOWN; + } + } + + if (man->geometry.rows == 0) { + if (man->geometry.cols == 0) { + ConsoleMessage("You specified a 0x0 window\n"); + ShutMeDown(0); + } else { + man->geometry.dir |= GROW_VERT; + } + man->geometry.rows = 1; + } else { + if (man->geometry.cols == 0) { + man->geometry.dir |= GROW_HORIZ; + man->geometry.cols = 1; + } else { + man->geometry.dir |= GROW_HORIZ | GROW_FIXED; + } + } + + man->geometry.width = man->geometry.cols * man->geometry.boxwidth; + man->geometry.height = man->geometry.rows * man->geometry.boxheight; + + if ((geometry_mask & XValue) && (geometry_mask & XNegative)) + man->geometry.x += globals.screenx - man->geometry.width; + if ((geometry_mask & YValue) && (geometry_mask & YNegative)) + man->geometry.y += globals.screeny - man->geometry.height; + + if (globals.transient) { + Window dummyroot, dummychild; + int junk; + + XQueryPointer(theDisplay, theRoot, &dummyroot, &dummychild, + &man->geometry.x, &man->geometry.y, &junk, &junk, &junk); + man->geometry.dir |= GROW_DOWN | GROW_RIGHT; + man->sizehints_flags |= USPosition; + } + + if (man->sizehints_flags & USPosition) { + if (man->geometry.dir & GROW_DOWN) { + if (man->geometry.dir & GROW_RIGHT) + man->gravity = NorthWestGravity; + else if (man->geometry.dir & GROW_LEFT) + man->gravity = NorthEastGravity; + else + ConsoleMessage( + "Internal error in X_init_manager\n"); + } else if (man->geometry.dir & GROW_UP) { + if (man->geometry.dir & GROW_RIGHT) + man->gravity = SouthWestGravity; + else if (man->geometry.dir & GROW_LEFT) + man->gravity = SouthEastGravity; + else + ConsoleMessage( + "Internal error in X_init_manager\n"); + } else { + ConsoleMessage("Internal error in X_init_manager\n"); + } + } else { + man->geometry.dir |= GROW_DOWN | GROW_RIGHT; + man->gravity = NorthWestGravity; + } } -void create_manager_window (int man_id) +void +create_manager_window(int man_id) { - XSizeHints sizehints; - XGCValues gcval; - unsigned long gcmask = 0; - unsigned long winattrmask = CWBackPixel| CWBorderPixel | CWEventMask | - CWBackingStore | CWBitGravity; - XSetWindowAttributes winattr; - unsigned int line_width = 1; - int line_style = LineSolid; - int cap_style = CapRound; - int join_style = JoinRound; - int i; - WinManager *man; - ConsoleDebug (X11, "In create_manager_window\n"); - - man = &globals.managers[man_id]; - - if (man->window_up) - return; - - size_manager (man); - - sizehints.flags = man->sizehints_flags; - - - sizehints.base_width = sizehints.width = man->geometry.width; - sizehints.base_height = sizehints.height = man->geometry.height; - sizehints.min_width = 0; - sizehints.max_width = globals.screenx; - sizehints.min_height = man->geometry.height; - sizehints.max_height = man->geometry.height; - sizehints.win_gravity = man->gravity; - sizehints.flags |= PBaseSize | PMinSize | PMaxSize | PWinGravity; - sizehints.x = man->geometry.x; - sizehints.y = man->geometry.y; - - - ConsoleDebug (X11, "hints: x, y, w, h = %d %d %d %d)\n", - sizehints.x, sizehints.y, - sizehints.base_width, sizehints.base_height); - ConsoleDebug (X11, "gravity: %d %d\n", sizehints.win_gravity, man->gravity); - - - winattr.background_pixel = man->backcolor[PLAIN_CONTEXT]; - winattr.border_pixel = man->forecolor[PLAIN_CONTEXT]; - winattr.backing_store = WhenMapped; - winattr.bit_gravity = man->gravity; - winattr.event_mask = ExposureMask | PointerMotionMask | EnterWindowMask | - LeaveWindowMask | KeyPressMask | StructureNotifyMask; - - if (globals.transient) - winattr.event_mask |= ButtonReleaseMask; - else - winattr.event_mask |= ButtonPressMask; - - man->theWindow = XCreateWindow (theDisplay, theRoot, sizehints.x, - sizehints.y, man->geometry.width, - man->geometry.height, - 0, CopyFromParent, InputOutput, - (Visual *)CopyFromParent, winattrmask, - &winattr); + XSizeHints sizehints; + XGCValues gcval; + unsigned long gcmask = 0; + unsigned long winattrmask = CWBackPixel | CWBorderPixel | CWEventMask | + CWBackingStore | CWBitGravity; + XSetWindowAttributes winattr; + unsigned int line_width = 1; + int line_style = LineSolid; + int cap_style = CapRound; + int join_style = JoinRound; + int i; + WinManager *man; + ConsoleDebug(X11, "In create_manager_window\n"); + + man = &globals.managers[man_id]; + + if (man->window_up) + return; + + size_manager(man); + + sizehints.flags = man->sizehints_flags; + + sizehints.base_width = sizehints.width = man->geometry.width; + sizehints.base_height = sizehints.height = man->geometry.height; + sizehints.min_width = 0; + sizehints.max_width = globals.screenx; + sizehints.min_height = man->geometry.height; + sizehints.max_height = man->geometry.height; + sizehints.win_gravity = man->gravity; + sizehints.flags |= PBaseSize | PMinSize | PMaxSize | PWinGravity; + sizehints.x = man->geometry.x; + sizehints.y = man->geometry.y; + + ConsoleDebug(X11, "hints: x, y, w, h = %d %d %d %d)\n", sizehints.x, + sizehints.y, sizehints.base_width, sizehints.base_height); + ConsoleDebug( + X11, "gravity: %d %d\n", sizehints.win_gravity, man->gravity); + + winattr.background_pixel = man->backcolor[PLAIN_CONTEXT]; + winattr.border_pixel = man->forecolor[PLAIN_CONTEXT]; + winattr.backing_store = WhenMapped; + winattr.bit_gravity = man->gravity; + winattr.event_mask = ExposureMask | PointerMotionMask | + EnterWindowMask | LeaveWindowMask | KeyPressMask | + StructureNotifyMask; + + if (globals.transient) + winattr.event_mask |= ButtonReleaseMask; + else + winattr.event_mask |= ButtonPressMask; + + man->theWindow = + XCreateWindow(theDisplay, theRoot, sizehints.x, sizehints.y, + man->geometry.width, man->geometry.height, 0, CopyFromParent, + InputOutput, (Visual *)CopyFromParent, winattrmask, &winattr); #ifdef SHAPE - XShapeSelectInput (theDisplay, man->theWindow, ShapeNotifyMask); + XShapeSelectInput(theDisplay, man->theWindow, ShapeNotifyMask); #endif - /* We really want the bit gravity to be NorthWest, so that can minimize - redraws. But, we had to have an appropriate bit gravity when creating - the window so that fvwm would place the window correctly if it has - a border. I don't know if I should wait until an event is received - before doing this. Sigh */ - winattr.bit_gravity = NorthWestGravity; - XChangeWindowAttributes (theDisplay, man->theWindow, - CWBitGravity, &winattr); - set_shape (man); - - man->theFrame = man->theWindow; - man->off_x = 0; - man->off_y = 0; - - for (i = 0; i < NUM_CONTEXTS; i++) { - man->backContext[i] = - XCreateGC (theDisplay, man->theWindow, gcmask, &gcval); - XSetForeground (theDisplay, man->backContext[i], man->backcolor[i]); - XSetLineAttributes (theDisplay, man->backContext[i], line_width, - line_style, cap_style, - join_style); - - man->hiContext[i] = - XCreateGC (theDisplay, man->theWindow, gcmask, &gcval); - XSetFont (theDisplay, man->hiContext[i], man->ButtonFont->fid); - XSetForeground (theDisplay, man->hiContext[i], man->forecolor[i]); - - gcmask = GCForeground | GCBackground; - gcval.foreground = man->backcolor[i]; - gcval.background = man->forecolor[i]; - man->flatContext[i] = XCreateGC (theDisplay, man->theWindow, - gcmask, &gcval); - if (theDepth > 2) { - gcmask = GCForeground | GCBackground; - gcval.foreground = man->hicolor[i]; - gcval.background = man->backcolor[i]; - man->reliefContext[i] = XCreateGC (theDisplay, man->theWindow, - gcmask, &gcval); - - gcmask = GCForeground | GCBackground; - gcval.foreground = man->shadowcolor[i]; - gcval.background = man->backcolor[i]; - man->shadowContext[i] = XCreateGC (theDisplay, man->theWindow, - gcmask, &gcval); - } - } - - set_window_properties (man->theWindow, man->titlename, - man->iconname, &sizehints); - man->window_up = 1; - map_manager (man); + /* We really want the bit gravity to be NorthWest, so that can minimize + redraws. But, we had to have an appropriate bit gravity when creating + the window so that fvwm would place the window correctly if it has + a border. I don't know if I should wait until an event is received + before doing this. Sigh */ + winattr.bit_gravity = NorthWestGravity; + XChangeWindowAttributes( + theDisplay, man->theWindow, CWBitGravity, &winattr); + set_shape(man); + + man->theFrame = man->theWindow; + man->off_x = 0; + man->off_y = 0; + + for (i = 0; i < NUM_CONTEXTS; i++) { + man->backContext[i] = + XCreateGC(theDisplay, man->theWindow, gcmask, &gcval); + XSetForeground( + theDisplay, man->backContext[i], man->backcolor[i]); + XSetLineAttributes(theDisplay, man->backContext[i], line_width, + line_style, cap_style, join_style); + + man->hiContext[i] = + XCreateGC(theDisplay, man->theWindow, gcmask, &gcval); + XSetFont(theDisplay, man->hiContext[i], man->ButtonFont->fid); + XSetForeground( + theDisplay, man->hiContext[i], man->forecolor[i]); + + gcmask = GCForeground | GCBackground; + gcval.foreground = man->backcolor[i]; + gcval.background = man->forecolor[i]; + man->flatContext[i] = + XCreateGC(theDisplay, man->theWindow, gcmask, &gcval); + if (theDepth > 2) { + gcmask = GCForeground | GCBackground; + gcval.foreground = man->hicolor[i]; + gcval.background = man->backcolor[i]; + man->reliefContext[i] = XCreateGC( + theDisplay, man->theWindow, gcmask, &gcval); + + gcmask = GCForeground | GCBackground; + gcval.foreground = man->shadowcolor[i]; + gcval.background = man->backcolor[i]; + man->shadowContext[i] = XCreateGC( + theDisplay, man->theWindow, gcmask, &gcval); + } + } + + set_window_properties( + man->theWindow, man->titlename, man->iconname, &sizehints); + man->window_up = 1; + map_manager(man); } -static int handle_error (Display *d, XErrorEvent *ev) +static int +handle_error(Display *d, XErrorEvent *ev) { - ConsoleMessage ("X Error:\n"); - ConsoleMessage (" error code: %d\n", ev->error_code); - ConsoleMessage (" request code: %d\n", ev->request_code); - ConsoleMessage (" minor code: %d\n", ev->minor_code); - ConsoleMessage ("Leaving a core dump now\n"); - abort(); - return 0; + ConsoleMessage("X Error:\n"); + ConsoleMessage(" error code: %d\n", ev->error_code); + ConsoleMessage(" request code: %d\n", ev->request_code); + ConsoleMessage(" minor code: %d\n", ev->minor_code); + ConsoleMessage("Leaving a core dump now\n"); + abort(); + return 0; } -void init_display (void) +void +init_display(void) { - theDisplay = XOpenDisplay (""); - if (theDisplay == NULL) { - ConsoleMessage ("Can't open display: %s\n", XDisplayName ("")); - ShutMeDown (1); - } - XSetErrorHandler (handle_error); - x_fd = XConnectionNumber (theDisplay); - theScreen = DefaultScreen (theDisplay); - theRoot = RootWindow (theDisplay, theScreen); - theDepth = DefaultDepth (theDisplay, theScreen); + theDisplay = XOpenDisplay(""); + if (theDisplay == NULL) { + ConsoleMessage("Can't open display: %s\n", XDisplayName("")); + ShutMeDown(1); + } + XSetErrorHandler(handle_error); + x_fd = XConnectionNumber(theDisplay); + theScreen = DefaultScreen(theDisplay); + theRoot = RootWindow(theDisplay, theScreen); + theDepth = DefaultDepth(theDisplay, theScreen); #ifdef TEST_MONO - theDepth = 2; + theDepth = 2; #endif - globals.screenx = DisplayWidth (theDisplay, theScreen); - globals.screeny = DisplayHeight (theDisplay, theScreen); + globals.screenx = DisplayWidth(theDisplay, theScreen); + globals.screeny = DisplayHeight(theDisplay, theScreen); #ifdef SHAPE - globals.shapes_supported = XShapeQueryExtension (theDisplay, &shapeEventBase, - &shapeErrorBase); + globals.shapes_supported = + XShapeQueryExtension(theDisplay, &shapeEventBase, &shapeErrorBase); #endif - InitPictureCMap (theDisplay, theRoot); + InitPictureCMap(theDisplay, theRoot); - ConsoleDebug (X11, "screen width: %ld\n", globals.screenx); - ConsoleDebug (X11, "screen height: %ld\n", globals.screeny); + ConsoleDebug(X11, "screen width: %ld\n", globals.screenx); + ConsoleDebug(X11, "screen height: %ld\n", globals.screeny); } Index: fvwm/modules/FvwmIconMan/x.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/x.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/x.h --- fvwm/modules/FvwmIconMan/x.h +++ fvwm/modules/FvwmIconMan/x.h @@ -1,6 +1,10 @@ #ifndef IN_X_H #define IN_X_H +#include + +#include "FvwmIconMan.h" + #ifdef SHAPE #include #endif @@ -9,14 +13,14 @@ extern Display *theDisplay; extern Window theRoot; extern int theDepth, theScreen; -extern void unmap_manager (WinManager *man); -extern void map_manager (WinManager *man); +extern void unmap_manager(WinManager *man); +extern void map_manager(WinManager *man); -extern Window find_frame_window (Window win, int *off_x, int *off_y); +extern Window find_frame_window(Window win, int *off_x, int *off_y); -extern void init_display (void); -extern void xevent_loop (void); -extern void create_manager_window (int man_id); -extern void X_init_manager (int man_id); +extern void init_display(void); +extern void xevent_loop(void); +extern void create_manager_window(int man_id); +extern void X_init_manager(int man_id); #endif Index: fvwm/modules/FvwmIconMan/xmanager.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/xmanager.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/xmanager.c --- fvwm/modules/FvwmIconMan/xmanager.c +++ fvwm/modules/FvwmIconMan/xmanager.c @@ -1,12 +1,14 @@ -#include "config.h" +#include "xmanager.h" #include +#include + #include "FvwmIconMan.h" +#include "config.h" #include "x.h" -#include "xmanager.h" static char const rcsid[] = - "$Id: xmanager.c,v 1.1.1.1 2006/11/26 10:53:51 matthieu Exp $"; + "$Id: xmanager.c,v 1.1.1.1 2006/11/26 10:53:51 matthieu Exp $"; #ifdef SHAPE #include @@ -19,1432 +21,1497 @@ static char const rcsid[] = #endif /* button dirty bits: */ -#define ICON_STATE_CHANGED 1 -#define STATE_CHANGED 2 -#define PICTURE_CHANGED 4 -#define WINDOW_CHANGED 8 -#define STRING_CHANGED 16 -#define REDRAW_BUTTON 32 -#define GEOMETRY_CHANGED 64 +#define ICON_STATE_CHANGED 1 +#define STATE_CHANGED 2 +#define PICTURE_CHANGED 4 +#define WINDOW_CHANGED 8 +#define STRING_CHANGED 16 +#define REDRAW_BUTTON 32 +#define GEOMETRY_CHANGED 64 /* manager dirty bits: */ /* GEOMETRY_CHANGED 64 same as with button */ -#define MAPPING_CHANGED 2 -#define SHAPE_CHANGED 4 -#define REDRAW_MANAGER 8 +#define MAPPING_CHANGED 2 +#define SHAPE_CHANGED 4 +#define REDRAW_MANAGER 8 /* ButtonArray dirty bits: */ #define NUM_BUTTONS_CHANGED 1 #define NUM_WINDOWS_CHANGED 2 -#define ALL_CHANGED 0x7f /* high bit is special */ +#define ALL_CHANGED 0x7f /* high bit is special */ typedef struct { - int button_x, button_y, button_h, button_w; /* dim's of the whole button */ - int icon_x, icon_y, icon_h, icon_w; /* what denotes icon state */ - int text_x, text_y, text_h, text_w; /* text field */ - int text_base; /* text baseline */ + int button_x, button_y, button_h, + button_w; /* dim's of the whole button */ + int icon_x, icon_y, icon_h, icon_w; /* what denotes icon state */ + int text_x, text_y, text_h, text_w; /* text field */ + int text_base; /* text baseline */ } ButtonGeometry; -static void print_button_info (Button *b); -static void insert_windows_button (WinData *win); +static void print_button_info(Button *b); +static void insert_windows_button(WinData *win); /***************************************************************************/ /* Utility leaf functions */ /***************************************************************************/ -static int selected_button_in_man (WinManager *man) +static int +selected_button_in_man(WinManager *man) { - assert (man); - ConsoleDebug (X11, "selected_button_in_man: %p\n", - globals.select_win); - if (globals.select_win && globals.select_win->button && - globals.select_win->manager == man) { - return globals.select_win->button->index; - } - return -1; + assert(man); + ConsoleDebug(X11, "selected_button_in_man: %p\n", globals.select_win); + if (globals.select_win && globals.select_win->button && + globals.select_win->manager == man) { + return globals.select_win->button->index; + } + return -1; } -static void ClipRectangle (WinManager *man, int context, - int x, int y, int w, int h) +static void +ClipRectangle(WinManager *man, int context, int x, int y, int w, int h) { - XRectangle r; + XRectangle r; - r.x = x; - r.y = y; - r.width = w; - r.height = h; + r.x = x; + r.y = y; + r.width = w; + r.height = h; - XSetClipRectangles(theDisplay, man->hiContext[context], 0, 0, &r, 1, - YXBanded); + XSetClipRectangles( + theDisplay, man->hiContext[context], 0, 0, &r, 1, YXBanded); } -static int num_visible_rows (int n, int cols) +static int +num_visible_rows(int n, int cols) { - return (n - 1) / cols + 1; + return (n - 1) / cols + 1; } -static int first_row_len (int n, int cols) +static int +first_row_len(int n, int cols) { - int ret = n % cols; - if (ret == 0) - ret = cols; - return ret; + int ret = n % cols; + if (ret == 0) + ret = cols; + return ret; } -static int index_to_box (WinManager *man, int index) +static int +index_to_box(WinManager *man, int index) { - int first_len, n, cols; + int first_len, n, cols; - if (man->geometry.dir & GROW_DOWN) { - return index; - } - else { - n = man->buttons.num_windows; - cols = man->geometry.cols; - first_len = first_row_len (n, cols); - if (index >= first_len) - index += cols - first_len; - index += (man->geometry.rows - num_visible_rows (n, cols)) * cols; - return index; - } + if (man->geometry.dir & GROW_DOWN) { + return index; + } else { + n = man->buttons.num_windows; + cols = man->geometry.cols; + first_len = first_row_len(n, cols); + if (index >= first_len) + index += cols - first_len; + index += + (man->geometry.rows - num_visible_rows(n, cols)) * cols; + return index; + } } -static int box_to_index (WinManager *man, int box) +static int +box_to_index(WinManager *man, int box) { - int first_len, n, cols; + int first_len, n, cols; - if (man->geometry.dir & GROW_DOWN) { - return box; - } - else { - n = man->buttons.num_windows; - cols = man->geometry.cols; - first_len = first_row_len (n, cols); + if (man->geometry.dir & GROW_DOWN) { + return box; + } else { + n = man->buttons.num_windows; + cols = man->geometry.cols; + first_len = first_row_len(n, cols); - box -= (man->geometry.rows - num_visible_rows (n, cols)) * cols; - if (!((box >= 0 && box < first_len) || box >= cols)) - return -1; - if (box >= first_len) - box -= cols - first_len; - return box; - } + box -= (man->geometry.rows - num_visible_rows(n, cols)) * cols; + if (!((box >= 0 && box < first_len) || box >= cols)) + return -1; + if (box >= first_len) + box -= cols - first_len; + return box; + } } -static int index_to_row (WinManager *man, int index) +static int +index_to_row(WinManager *man, int index) { - int row; + int row; - row = index_to_box (man, index) / man->geometry.cols; + row = index_to_box(man, index) / man->geometry.cols; - return row; + return row; } -static int index_to_col (WinManager *man, int index) +static int +index_to_col(WinManager *man, int index) { - int col; + int col; - col = index_to_box (man, index) % man->geometry.cols; + col = index_to_box(man, index) % man->geometry.cols; - return col; + return col; } -static int rects_equal (XRectangle *x, XRectangle *y) +static int +rects_equal(XRectangle *x, XRectangle *y) { - return (x->x == y->x) && (x->y == y->y) && (x->width == y->width) && - (x->height == y->height); + return (x->x == y->x) && (x->y == y->y) && (x->width == y->width) && + (x->height == y->height); } -static int top_y_coord (WinManager *man) +static int +top_y_coord(WinManager *man) { - if (man->buttons.num_windows > 0 && (man->geometry.dir & GROW_UP)) { - return index_to_row (man, 0) * man->geometry.boxheight; - } - else { - return 0; - } + if (man->buttons.num_windows > 0 && (man->geometry.dir & GROW_UP)) { + return index_to_row(man, 0) * man->geometry.boxheight; + } else { + return 0; + } } -static ManGeometry *figure_geometry (WinManager *man) +static ManGeometry * +figure_geometry(WinManager *man) { - /* Given the number of wins in icon_list and width x height, compute - new geometry. */ - /* if GROW_FIXED is set, don't change window geometry */ + /* Given the number of wins in icon_list and width x height, compute + new geometry. */ + /* if GROW_FIXED is set, don't change window geometry */ - static ManGeometry ret; - ManGeometry *g = &man->geometry; - int n = man->buttons.num_windows; + static ManGeometry ret; + ManGeometry *g = &man->geometry; + int n = man->buttons.num_windows; - ret = *g; + ret = *g; - ConsoleDebug (X11, "figure_geometry: %s: %d, %d %d %d %d\n", - man->titlename, n, - ret.width, ret.height, ret.cols, ret.rows); + ConsoleDebug(X11, "figure_geometry: %s: %d, %d %d %d %d\n", + man->titlename, n, ret.width, ret.height, ret.cols, ret.rows); - if (n == 0) { - n = 1; - } + if (n == 0) { + n = 1; + } - if (man->geometry.dir & GROW_FIXED) { - ret.cols = num_visible_rows (n, g->rows); - ret.boxwidth = ret.width / ret.cols; - } - else { - if (man->geometry.dir & GROW_VERT) { - if (g->cols) { - ret.rows = num_visible_rows (n, g->cols); - } - else { - ConsoleMessage ("Internal error in figure_geometry\n"); - ret.rows = 1; - } - ret.height = ret.rows * g->boxheight; - ret.width = ret.cols * g->boxwidth; - } - else { - /* need to set resize inc */ - if (g->rows) { - ret.cols = num_visible_rows (n, g->rows); - } - else { - ConsoleMessage ("Internal error in figure_geometry\n"); - ret.cols = 1; - } - ret.height = ret.rows * g->boxheight; - ret.width = ret.cols * g->boxwidth; - } - } + if (man->geometry.dir & GROW_FIXED) { + ret.cols = num_visible_rows(n, g->rows); + ret.boxwidth = ret.width / ret.cols; + } else { + if (man->geometry.dir & GROW_VERT) { + if (g->cols) { + ret.rows = num_visible_rows(n, g->cols); + } else { + ConsoleMessage( + "Internal error in figure_geometry\n"); + ret.rows = 1; + } + ret.height = ret.rows * g->boxheight; + ret.width = ret.cols * g->boxwidth; + } else { + /* need to set resize inc */ + if (g->rows) { + ret.cols = num_visible_rows(n, g->rows); + } else { + ConsoleMessage( + "Internal error in figure_geometry\n"); + ret.cols = 1; + } + ret.height = ret.rows * g->boxheight; + ret.width = ret.cols * g->boxwidth; + } + } - ConsoleDebug (X11, "figure_geometry: %d %d %d %d %d\n", - n, ret.width, ret.height, ret.cols, ret.rows); + ConsoleDebug(X11, "figure_geometry: %d %d %d %d %d\n", n, ret.width, + ret.height, ret.cols, ret.rows); - return &ret; + return &ret; } -static ManGeometry *query_geometry (WinManager *man) +static ManGeometry * +query_geometry(WinManager *man) { - XWindowAttributes frame_attr, win_attr; - int off_x, off_y; - static ManGeometry g; + XWindowAttributes frame_attr, win_attr; + int off_x, off_y; + static ManGeometry g; - assert (man->window_mapped); + assert(man->window_mapped); - off_x = 0; - off_y = 0; - man->theFrame = find_frame_window (man->theWindow, &off_x, &off_y); - XGetWindowAttributes (theDisplay, man->theFrame, &frame_attr); - g.x = frame_attr.x + off_x + frame_attr.border_width; - g.y = frame_attr.y + off_y + frame_attr.border_width; - XGetWindowAttributes (theDisplay, man->theWindow, &win_attr); - g.width = win_attr.width; - g.height = win_attr.height; + off_x = 0; + off_y = 0; + man->theFrame = find_frame_window(man->theWindow, &off_x, &off_y); + XGetWindowAttributes(theDisplay, man->theFrame, &frame_attr); + g.x = frame_attr.x + off_x + frame_attr.border_width; + g.y = frame_attr.y + off_y + frame_attr.border_width; + XGetWindowAttributes(theDisplay, man->theWindow, &win_attr); + g.width = win_attr.width; + g.height = win_attr.height; - return &g; + return &g; } -static void fix_manager_size (WinManager *man, int w, int h) +static void +fix_manager_size(WinManager *man, int w, int h) { - XSizeHints size; - long mask; + XSizeHints size; + long mask = 0; + + if (!XGetWMNormalHints(theDisplay, man->theWindow, &size, &mask)) { + memset(&size, 0, sizeof(size)); + size.flags = 0; + } - XGetWMNormalHints (theDisplay, man->theWindow, &size, &mask); - size.min_width = w; - size.max_width = w; - size.min_height = h; - size.max_height = h; - XSetWMNormalHints (theDisplay, man->theWindow, &size); + size.flags |= PMinSize | PMaxSize | PBaseSize | PWinGravity; + size.min_width = w; + size.max_width = w; + size.min_height = h; + size.max_height = h; + size.base_width = w; + size.base_height = h; + size.win_gravity = man->gravity; + + XSetWMNormalHints(theDisplay, man->theWindow, &size); } /* Like XMoveResizeWindow(), but can move in arbitary directions */ -static void resize_window (WinManager *man) -{ - ManGeometry *g; - int x_changed, y_changed, dir; - - dir = man->geometry.dir; - fix_manager_size (man, man->geometry.width, man->geometry.height); - - if ((dir & GROW_DOWN) && (dir & GROW_RIGHT)) { - XResizeWindow (theDisplay, man->theWindow, man->geometry.width, - man->geometry.height); - } - else { - MyXGrabServer (theDisplay); - g = query_geometry (man); - x_changed = y_changed = 0; - if (dir & GROW_LEFT) { - man->geometry.x = g->x + g->width - man->geometry.width; - x_changed = 1; - } - else { - man->geometry.x = g->x; - } - if (dir & GROW_UP) { - man->geometry.y = g->y + g->height - man->geometry.height; - y_changed = 1; - } - else { - man->geometry.y = g->y; - } - - ConsoleDebug (X11, "queried: y: %d, h: %d, queried: %d\n", g->y, - man->geometry.height, g->height); - - if (x_changed || y_changed) { - XMoveResizeWindow (theDisplay, man->theWindow, - man->geometry.x, - man->geometry.y, - man->geometry.width, man->geometry.height); - } - else { - XResizeWindow (theDisplay, man->theWindow, man->geometry.width, - man->geometry.height); - } - MyXUngrabServer (theDisplay); - } -} - -static char *make_display_string (WinData *win, char *format, int len) +static void +resize_window(WinManager *man) +{ + ManGeometry *g; + int x_changed, y_changed, dir; + + dir = man->geometry.dir; + fix_manager_size(man, man->geometry.width, man->geometry.height); + + if ((dir & GROW_DOWN) && (dir & GROW_RIGHT)) { + XResizeWindow(theDisplay, man->theWindow, man->geometry.width, + man->geometry.height); + } else { + MyXGrabServer(theDisplay); + g = query_geometry(man); + x_changed = y_changed = 0; + if (dir & GROW_LEFT) { + man->geometry.x = g->x + g->width - man->geometry.width; + x_changed = 1; + } else { + man->geometry.x = g->x; + } + if (dir & GROW_UP) { + man->geometry.y = + g->y + g->height - man->geometry.height; + y_changed = 1; + } else { + man->geometry.y = g->y; + } + + ConsoleDebug(X11, "queried: y: %d, h: %d, queried: %d\n", g->y, + man->geometry.height, g->height); + + if (x_changed || y_changed) { + XMoveResizeWindow(theDisplay, man->theWindow, + man->geometry.x, man->geometry.y, + man->geometry.width, man->geometry.height); + } else { + XResizeWindow(theDisplay, man->theWindow, + man->geometry.width, man->geometry.height); + } + MyXUngrabServer(theDisplay); + } +} + +static char * +make_display_string(WinData *win, char *format, int len) { #define MAX_DISPLAY_SIZE 1024 -#define COPY(field) \ - temp_p = win->field; \ - if (temp_p) \ - while (*temp_p && out_p - buf < len - 1) \ - *out_p++ = *temp_p++; \ - in_p++; - - static char buf[MAX_DISPLAY_SIZE]; - char *string, *in_p, *out_p, *temp_p; - - in_p = format; - out_p = buf; - - if (len > MAX_DISPLAY_SIZE || len <= 0) - len = MAX_DISPLAY_SIZE; - - while (*in_p && out_p - buf < len - 1) { - if (*in_p == '%') { - switch (*(++in_p)) { - case 'i': - COPY (iconname); - break; - - case 't': - COPY (titlename); - break; - - case 'r': - COPY (resname); - break; - - case 'c': - COPY (classname); - break; - - default: - *out_p++ = *in_p++; - break; - } - } - else { - *out_p++ = *in_p++; - } - } - - *out_p++ = '\0'; - - string = buf; - return string; +#define COPY(field) \ + temp_p = win->field; \ + if (temp_p) \ + while (*temp_p && out_p - buf < len - 1) \ + *out_p++ = *temp_p++; \ + in_p++; + + static char buf[MAX_DISPLAY_SIZE]; + char *string, *in_p, *out_p, *temp_p; + + in_p = format; + out_p = buf; + + if (len > MAX_DISPLAY_SIZE || len <= 0) + len = MAX_DISPLAY_SIZE; + + while (*in_p && out_p - buf < len - 1) { + if (*in_p == '%') { + switch (*(++in_p)) { + case 'i': + COPY(iconname); + break; + + case 't': + COPY(titlename); + break; + + case 'r': + COPY(resname); + break; + + case 'c': + COPY(classname); + break; + + default: + *out_p++ = *in_p++; + break; + } + } else { + *out_p++ = *in_p++; + } + } + + *out_p++ = '\0'; + + string = buf; + return string; #undef COPY #undef MAX_DISPLAY_SIZE } -Button *button_above (WinManager *man, Button *b) +Button * +button_above(WinManager *man, Button *b) { - int n = man->buttons.num_windows, cols = man->geometry.cols; - int i = -1; + int n = man->buttons.num_windows, cols = man->geometry.cols; + int i = -1; - if (b) { - i = box_to_index (man, index_to_box (man, b->index) - cols); - } - if (i < 0 || i >= n) - return b; - else - return man->buttons.buttons[i]; + if (b) { + i = box_to_index(man, index_to_box(man, b->index) - cols); + } + if (i < 0 || i >= n) + return b; + else + return man->buttons.buttons[i]; } -Button *button_below (WinManager *man, Button *b) +Button * +button_below(WinManager *man, Button *b) { - int n = man->buttons.num_windows; - int i = -1; + int n = man->buttons.num_windows; + int i = -1; - if (b) { - i = box_to_index (man, index_to_box (man, b->index) + man->geometry.cols); - } - if (i < 0 || i >= n) - return b; - else - return man->buttons.buttons[i]; + if (b) { + i = box_to_index( + man, index_to_box(man, b->index) + man->geometry.cols); + } + if (i < 0 || i >= n) + return b; + else + return man->buttons.buttons[i]; } -Button *button_right (WinManager *man, Button *b) +Button * +button_right(WinManager *man, Button *b) { - int i = 0; + int i = 0; - if (index_to_col (man, b->index) < man->geometry.cols - 1) { - i = box_to_index (man, index_to_box (man, b->index) + 1); - } + if (index_to_col(man, b->index) < man->geometry.cols - 1) { + i = box_to_index(man, index_to_box(man, b->index) + 1); + } - if (i < 0 || i >= man->buttons.num_windows) - return b; - else - return man->buttons.buttons[i]; + if (i < 0 || i >= man->buttons.num_windows) + return b; + else + return man->buttons.buttons[i]; } -Button *button_left (WinManager *man, Button *b) +Button * +button_left(WinManager *man, Button *b) { - int i; - if (index_to_col (man, b->index) > 0) { - i = box_to_index (man, index_to_box (man, b->index) - 1); - } + int i; + if (index_to_col(man, b->index) > 0) { + i = box_to_index(man, index_to_box(man, b->index) - 1); + } - if (i < 0 || i >= man->buttons.num_windows) - return b; - else - return man->buttons.buttons[i]; + if (i < 0 || i >= man->buttons.num_windows) + return b; + else + return man->buttons.buttons[i]; } -Button *button_next (WinManager *man, Button *b) +Button * +button_next(WinManager *man, Button *b) { - int i = b->index + 1; + int i = b->index + 1; - if (i >= 0 && i < man->buttons.num_windows) - return man->buttons.buttons[i]; - else - return b; + if (i >= 0 && i < man->buttons.num_windows) + return man->buttons.buttons[i]; + else + return b; } -Button *button_prev (WinManager *man, Button *b) +Button * +button_prev(WinManager *man, Button *b) { - int i = b->index - 1; + int i = b->index - 1; - if (i >= 0 && i < man->buttons.num_windows) - return man->buttons.buttons[i]; - else - return b; + if (i >= 0 && i < man->buttons.num_windows) + return man->buttons.buttons[i]; + else + return b; } -Button *xy_to_button (WinManager *man, int x, int y) +Button * +xy_to_button(WinManager *man, int x, int y) { - int row = y / man->geometry.boxheight; - int col = x / man->geometry.boxwidth; - int box, index; + int row = y / man->geometry.boxheight; + int col = x / man->geometry.boxwidth; + int box, index; - if (x >= 0 && x <= man->geometry.width && - y >= 0 && y <= man->geometry.height) { - box = row * man->geometry.cols + col; - index = box_to_index (man, box); - if (index >= 0 && index < man->buttons.num_windows) - return man->buttons.buttons[index]; - } + if (x >= 0 && x <= man->geometry.width && y >= 0 && + y <= man->geometry.height) { + box = row * man->geometry.cols + col; + index = box_to_index(man, box); + if (index >= 0 && index < man->buttons.num_windows) + return man->buttons.buttons[index]; + } - return NULL; + return NULL; } /***************************************************************************/ /* Routines which change dirtyable state */ /***************************************************************************/ -static void set_button_geometry (WinManager *man, Button *box) +static void +set_button_geometry(WinManager *man, Button *box) { - box->x = index_to_col (man, box->index) * man->geometry.boxwidth; - box->y = index_to_row (man, box->index) * man->geometry.boxheight; - box->w = man->geometry.boxwidth; - box->h = man->geometry.boxheight; - box->drawn_state.dirty_flags |= GEOMETRY_CHANGED; + box->x = index_to_col(man, box->index) * man->geometry.boxwidth; + box->y = index_to_row(man, box->index) * man->geometry.boxheight; + box->w = man->geometry.boxwidth; + box->h = man->geometry.boxheight; + box->drawn_state.dirty_flags |= GEOMETRY_CHANGED; } -static void clear_button (Button *b) +static void +clear_button(Button *b) { - assert (b); - b->drawn_state.win = NULL; - b->drawn_state.dirty_flags = REDRAW_BUTTON; + assert(b); + b->drawn_state.win = NULL; + b->drawn_state.dirty_flags = REDRAW_BUTTON; } -static void set_window_button (WinData *win, int index) +static void +set_window_button(WinData *win, int index) { - Button *b; + Button *b; - assert (win->manager && index < win->manager->buttons.num_buttons); + assert(win->manager && index < win->manager->buttons.num_buttons); - b = win->manager->buttons.buttons[index]; + b = win->manager->buttons.buttons[index]; - /* Can optimize here */ + /* Can optimize here */ #ifdef MINI_ICONS - b->drawn_state.pic = win->pic; + b->drawn_state.pic = win->pic; #endif - b->drawn_state.win = win; - b->drawn_state.display_string = win->display_string; - b->drawn_state.iconified = win->iconified; - b->drawn_state.state = win->state; - b->drawn_state.dirty_flags = ALL_CHANGED; - - win->button = b; -} + b->drawn_state.win = win; + b->drawn_state.display_string = win->display_string; + b->drawn_state.iconified = win->iconified; + b->drawn_state.state = win->state; + b->drawn_state.dirty_flags = ALL_CHANGED; -static void *Realloc (void *ptr, int size) -{ - if (ptr == NULL) - return safemalloc (size); - else - return realloc (ptr, size); + win->button = b; } -static void set_num_buttons (ButtonArray *buttons, int n) +static void +set_num_buttons(ButtonArray *buttons, int n) { - int i; + int i; - ConsoleDebug (X11, "set_num_buttons: %d %d\n", buttons->num_buttons, n); + ConsoleDebug(X11, "set_num_buttons: %d %d\n", buttons->num_buttons, n); - if (n > buttons->num_buttons) { - buttons->dirty_flags |= NUM_BUTTONS_CHANGED; - buttons->buttons = (Button **)Realloc (buttons->buttons, - n * sizeof (Button *)); - if (buttons->buttons == NULL) { - ConsoleMessage ("Realloc failed! Bailing out\n"); - ShutMeDown(1); - } + if (n > buttons->num_buttons) { + buttons->dirty_flags |= NUM_BUTTONS_CHANGED; + buttons->buttons = + (Button **)xreallocarray(buttons->buttons, n, + sizeof(Button *)); - for (i = buttons->num_buttons; i < n; i++) { - buttons->buttons[i] = (Button *)safemalloc (sizeof (Button)); - buttons->buttons[i]->index = i; - buttons->buttons[i]->drawn_state.dirty_flags = 0; - buttons->buttons[i]->drawn_state.w = 0; - buttons->buttons[i]->drawn_state.h = 0; - buttons->buttons[i]->drawn_state.win = NULL; - } + for (i = buttons->num_buttons; i < n; i++) { + buttons->buttons[i] = + (Button *)xmalloc(sizeof(Button)); + buttons->buttons[i]->index = i; + buttons->buttons[i]->drawn_state.dirty_flags = 0; + buttons->buttons[i]->drawn_state.w = 0; + buttons->buttons[i]->drawn_state.h = 0; + buttons->buttons[i]->drawn_state.win = NULL; + } - buttons->dirty_flags |= NUM_BUTTONS_CHANGED; - buttons->num_buttons = n; - } + buttons->dirty_flags |= NUM_BUTTONS_CHANGED; + buttons->num_buttons = n; + } } -static void increase_num_windows (ButtonArray *buttons, int off) +static void +increase_num_windows(ButtonArray *buttons, int off) { - int n; + int n; - if (off != 0) { - buttons->num_windows += off; - buttons->dirty_flags |= NUM_WINDOWS_CHANGED; + if (off != 0) { + buttons->num_windows += off; + buttons->dirty_flags |= NUM_WINDOWS_CHANGED; - if (buttons->num_windows > buttons->num_buttons) { - n = buttons->num_windows + 10; - set_num_buttons (buttons, n); - } - } + if (buttons->num_windows > buttons->num_buttons) { + n = buttons->num_windows + 10; + set_num_buttons(buttons, n); + } + } } -static void set_man_gravity_origin (WinManager *man) +static void +set_man_gravity_origin(WinManager *man) { - if (man->gravity == NorthWestGravity || man->gravity == NorthEastGravity) - man->geometry.gravity_y = 0; - else - man->geometry.gravity_y = man->geometry.height; - if (man->gravity == NorthWestGravity || man->gravity == SouthWestGravity) - man->geometry.gravity_x = 0; - else - man->geometry.gravity_x = man->geometry.width; + if (man->gravity == NorthWestGravity || + man->gravity == NorthEastGravity) + man->geometry.gravity_y = 0; + else + man->geometry.gravity_y = man->geometry.height; + if (man->gravity == NorthWestGravity || + man->gravity == SouthWestGravity) + man->geometry.gravity_x = 0; + else + man->geometry.gravity_x = man->geometry.width; } -static void set_man_geometry (WinManager *man, ManGeometry *new) +static void +set_man_geometry(WinManager *man, ManGeometry *new) { - int n; + int n; - if (man->geometry.width != new->width || - man->geometry.height != new->height || - man->geometry.rows != new->rows || - man->geometry.cols != new->cols || - man->geometry.boxheight != new->boxheight || - man->geometry.boxwidth != new->boxwidth) { - man->dirty_flags |= GEOMETRY_CHANGED; - } + if (man->geometry.width != new->width || + man->geometry.height != new->height || + man->geometry.rows != new->rows || + man->geometry.cols != new->cols || + man->geometry.boxheight != new->boxheight || + man->geometry.boxwidth != new->boxwidth) { + man->dirty_flags |= GEOMETRY_CHANGED; + } - man->geometry = *new; - set_man_gravity_origin (man); - n = man->geometry.rows * man->geometry.cols; - if (man->buttons.num_buttons < n) - set_num_buttons (&man->buttons, n + 10); + man->geometry = *new; + set_man_gravity_origin(man); + n = man->geometry.rows * man->geometry.cols; + if (man->buttons.num_buttons < n) + set_num_buttons(&man->buttons, n + 10); } -void set_manager_width (WinManager *man, int width) +void +set_manager_width(WinManager *man, int width) { - if (width != man->geometry.width) { - ConsoleDebug (X11, "set_manager_width: %d -> %d, %d -> %d\n", - man->geometry.width, width, man->geometry.boxwidth, - width / man->geometry.cols); - man->geometry.width = width; - man->geometry.boxwidth = width / man->geometry.cols; - man->dirty_flags |= GEOMETRY_CHANGED; - } + if (width != man->geometry.width) { + ConsoleDebug(X11, "set_manager_width: %d -> %d, %d -> %d\n", + man->geometry.width, width, man->geometry.boxwidth, + width / man->geometry.cols); + man->geometry.width = width; + man->geometry.boxwidth = width / man->geometry.cols; + man->dirty_flags |= GEOMETRY_CHANGED; + } } -void force_manager_redraw (WinManager *man) +void +force_manager_redraw(WinManager *man) { - man->dirty_flags |= REDRAW_MANAGER; - draw_manager (man); + man->dirty_flags |= REDRAW_MANAGER; + draw_manager(man); } #ifdef MINI_ICONS -void set_win_picture (WinData *win, Pixmap picture, Pixmap mask, - unsigned int depth, unsigned int width, - unsigned int height) +void +set_win_picture(WinData *win, Pixmap picture, Pixmap mask, unsigned int depth, + unsigned int width, unsigned int height) { - if (win->button) - win->button->drawn_state.dirty_flags |= PICTURE_CHANGED; - win->pic.picture = picture; - win->pic.mask = mask; - win->pic.width = width; - win->pic.height = height; - win->pic.depth = depth; + if (win->button) + win->button->drawn_state.dirty_flags |= PICTURE_CHANGED; + win->pic.picture = picture; + win->pic.mask = mask; + win->pic.width = width; + win->pic.height = height; + win->pic.depth = depth; } #endif -void set_win_iconified (WinData *win, int iconified) +void +set_win_iconified(WinData *win, int iconified) { - if (win->button && win->iconified != iconified) - win->button->drawn_state.dirty_flags |= ICON_STATE_CHANGED; - win->iconified = iconified; + if (win->button && win->iconified != iconified) + win->button->drawn_state.dirty_flags |= ICON_STATE_CHANGED; + win->iconified = iconified; } -void set_win_state (WinData *win, int state) +void +set_win_state(WinData *win, int state) { - if (win->button && win->state != state) - win->button->drawn_state.dirty_flags |= STATE_CHANGED; - win->state = state; + if (win->button && win->state != state) + win->button->drawn_state.dirty_flags |= STATE_CHANGED; + win->state = state; } -void add_win_state (WinData *win, int flag) +void +add_win_state(WinData *win, int flag) { - if (win->button && (win->state & flag) == 0) - win->button->drawn_state.dirty_flags |= STATE_CHANGED; - win->state |= flag; - ConsoleDebug (X11, "add_win_state: %s 0x%x\n", win->titlename, flag); + if (win->button && (win->state & flag) == 0) + win->button->drawn_state.dirty_flags |= STATE_CHANGED; + win->state |= flag; + ConsoleDebug(X11, "add_win_state: %s 0x%x\n", win->titlename, flag); } -void del_win_state (WinData *win, int flag) +void +del_win_state(WinData *win, int flag) { - if (win->button && (win->state & flag)) - win->button->drawn_state.dirty_flags |= STATE_CHANGED; - win->state &= ~flag; - ConsoleDebug (X11, "del_win_state: %s 0x%x\n", win->titlename, flag); + if (win->button && (win->state & flag)) + win->button->drawn_state.dirty_flags |= STATE_CHANGED; + win->state &= ~flag; + ConsoleDebug(X11, "del_win_state: %s 0x%x\n", win->titlename, flag); } -void set_win_displaystring (WinData *win) +void +set_win_displaystring(WinData *win) { - WinManager *man = win->manager; - int maxlen; + WinManager *man = win->manager; + int maxlen; + int used_resource_placeholder = 0; - if (!man || ((man->format_depend & CLASS_NAME) && !win->classname) - || ((man->format_depend & ICON_NAME) && !win->iconname) - || ((man->format_depend & TITLE_NAME) && !win->titlename) - || ((man->format_depend & RESOURCE_NAME) && !win->resname)) { - return; - } + if (!man || ((man->format_depend & CLASS_NAME) && !win->classname) || + ((man->format_depend & ICON_NAME) && !win->iconname) || + ((man->format_depend & TITLE_NAME) && !win->titlename)) { + return; + } - if (man->window_up) { - assert (man->geometry.width && man->fontwidth); - maxlen = man->geometry.width / man->fontwidth + 2 /* fudge factor */; - } - else { - maxlen = 0; - } - copy_string (&win->display_string, - make_display_string (win, man->formatstring, maxlen)); - if (win->button) - win->button->drawn_state.dirty_flags |= STRING_CHANGED; + if ((man->format_depend & RESOURCE_NAME) && !win->resname) { + win->resname = ""; + used_resource_placeholder = 1; + } + + if (man->window_up) { + assert(man->geometry.width && man->fontwidth); + maxlen = + man->geometry.width / man->fontwidth + 2 /* fudge factor */; + } else { + maxlen = 0; + } + copy_string(&win->display_string, + make_display_string(win, man->formatstring, maxlen)); + if (used_resource_placeholder) + win->resname = NULL; + if (win->button) + win->button->drawn_state.dirty_flags |= STRING_CHANGED; } /* This function is here and not with the other static utility functions because it basically is the inverse of set_shape() */ -static void clear_empty_region (WinManager *man) -{ - XRectangle rects[2]; - int num_rects = 0, n = man->buttons.num_windows, cols = man->geometry.cols; - int rows = man->geometry.rows; - int boxheight = man->geometry.boxheight; - - if (man->shaped) - return; - - rects[1].x = rects[1].y = rects[1].width = rects[1].height = 0; - - if (n == 0 || rows * cols == 0 /* just be to safe */) { - rects[0].x = 0; - rects[0].y = 0; - rects[0].width = man->geometry.width; - rects[0].height = man->geometry.height; - num_rects = 1; - } - else if (man->geometry.dir & GROW_DOWN) { - assert (cols); - if (n % cols == 0) { - rects[0].x = 0; - rects[0].y = num_visible_rows (n, cols) * man->geometry.boxheight; - rects[0].width = man->geometry.width; - rects[0].height = man->geometry.height - rects[0].y; - num_rects = 1; - } - else { - rects[0].x = (n % cols) * man->geometry.boxwidth; - rects[0].y = (num_visible_rows (n, cols) - 1) * man->geometry.boxheight; - rects[0].width = man->geometry.width - rects[0].y; - rects[0].height = boxheight; - rects[1].x = 0; - rects[1].y = rects[0].y + rects[0].height; - rects[1].width = man->geometry.width; - rects[1].height = man->geometry.height - rects[0].y; - num_rects = 2; - } - } - else { - assert (cols); - /* for shaped windows, we won't see this part of the window */ - if (n % cols == 0) { - rects[0].x = 0; - rects[0].y = 0; - rects[0].width = man->geometry.width; - rects[0].height = top_y_coord (man); - num_rects = 1; - } - else { - rects[0].x = 0; - rects[0].y = 0; - rects[0].width = man->geometry.width; - rects[0].height = top_y_coord (man); - rects[1].x = (n % cols) * man->geometry.boxwidth; - rects[1].y = rects[0].height; - rects[1].width = man->geometry.width - rects[1].x; - rects[1].height = boxheight; - num_rects = 2; - } - } - - ConsoleDebug (X11, "Clearing: %d: (%d, %d, %d, %d) + (%d, %d, %d, %d)\n", - num_rects, - rects[0].x, rects[0].y, rects[0].width, rects[0].height, - rects[1].x, rects[1].y, rects[1].width, rects[1].height); - - XFillRectangles (theDisplay, man->theWindow, - man->backContext[PLAIN_CONTEXT], rects, num_rects); -} - -void set_shape (WinManager *man) +static void +clear_empty_region(WinManager *man) +{ + XRectangle rects[2]; + int num_rects = 0, n = man->buttons.num_windows, + cols = man->geometry.cols; + int rows = man->geometry.rows; + int boxheight = man->geometry.boxheight; + + if (man->shaped) + return; + + rects[1].x = rects[1].y = rects[1].width = rects[1].height = 0; + + if (n == 0 || rows * cols == 0 /* just be to safe */) { + rects[0].x = 0; + rects[0].y = 0; + rects[0].width = man->geometry.width; + rects[0].height = man->geometry.height; + num_rects = 1; + } else if (man->geometry.dir & GROW_DOWN) { + assert(cols); + if (n % cols == 0) { + rects[0].x = 0; + rects[0].y = + num_visible_rows(n, cols) * man->geometry.boxheight; + rects[0].width = man->geometry.width; + rects[0].height = man->geometry.height - rects[0].y; + num_rects = 1; + } else { + rects[0].x = (n % cols) * man->geometry.boxwidth; + rects[0].y = (num_visible_rows(n, cols) - 1) * + man->geometry.boxheight; + rects[0].width = man->geometry.width - rects[0].y; + rects[0].height = boxheight; + rects[1].x = 0; + rects[1].y = rects[0].y + rects[0].height; + rects[1].width = man->geometry.width; + rects[1].height = man->geometry.height - rects[0].y; + num_rects = 2; + } + } else { + assert(cols); + /* for shaped windows, we won't see this part of the window */ + if (n % cols == 0) { + rects[0].x = 0; + rects[0].y = 0; + rects[0].width = man->geometry.width; + rects[0].height = top_y_coord(man); + num_rects = 1; + } else { + rects[0].x = 0; + rects[0].y = 0; + rects[0].width = man->geometry.width; + rects[0].height = top_y_coord(man); + rects[1].x = (n % cols) * man->geometry.boxwidth; + rects[1].y = rects[0].height; + rects[1].width = man->geometry.width - rects[1].x; + rects[1].height = boxheight; + num_rects = 2; + } + } + + ConsoleDebug(X11, "Clearing: %d: (%d, %d, %d, %d) + (%d, %d, %d, %d)\n", + num_rects, rects[0].x, rects[0].y, rects[0].width, rects[0].height, + rects[1].x, rects[1].y, rects[1].width, rects[1].height); + + XFillRectangles(theDisplay, man->theWindow, + man->backContext[PLAIN_CONTEXT], rects, num_rects); +} + +void +set_shape(WinManager *man) { #ifdef SHAPE - int n; - XRectangle rects[2]; - int cols = man->geometry.cols; - - if (!globals.shapes_supported || man->shaped == 0) - return; - - ConsoleDebug (X11, "in set_shape: %s\n", man->titlename); - - n = man->buttons.num_windows; - if (n == 0) - n = 1; - - if (cols == 0 || n % cols == 0) { - rects[0].x = 0; - rects[0].y = top_y_coord (man); - rects[0].width = man->geometry.width; - rects[0].height = num_visible_rows (n, cols) * man->geometry.boxheight; - if (man->shape.num_rects != 1 || !rects_equal (rects, man->shape.rects)) { - man->dirty_flags |= SHAPE_CHANGED; - } - man->shape.num_rects = 1; - man->shape.rects[0] = rects[0]; - } - else { - if (man->geometry.dir & GROW_DOWN) { - rects[0].x = 0; - rects[0].y = 0; - rects[0].width = man->geometry.width; - rects[0].height = - (num_visible_rows (n, cols) - 1) * man->geometry.boxheight; - rects[1].x = 0; - rects[1].y = rects[0].height; - rects[1].width = (n % cols) * man->geometry.boxwidth; - rects[1].height = man->geometry.boxheight; - } - else { - rects[0].x = 0; - rects[0].y = top_y_coord (man); - rects[0].width = (n % cols) * man->geometry.boxwidth; - rects[0].height = man->geometry.boxheight; - rects[1].x = 0; - rects[1].y = rects[0].y + rects[0].height; - rects[1].width = man->geometry.width; - rects[1].height = (num_visible_rows (n, cols) - 1) * - man->geometry.boxheight; - } - if (man->shape.num_rects != 2 || - !rects_equal (rects, man->shape.rects) || - !rects_equal (rects + 1, man->shape.rects + 1)) { - man->dirty_flags |= SHAPE_CHANGED; - } - man->shape.num_rects = 2; - man->shape.rects[0] = rects[0]; - man->shape.rects[1] = rects[1]; - } + int n; + XRectangle rects[2]; + int cols = man->geometry.cols; + + if (!globals.shapes_supported || man->shaped == 0) + return; + + ConsoleDebug(X11, "in set_shape: %s\n", man->titlename); + + n = man->buttons.num_windows; + if (n == 0) + n = 1; + + if (cols == 0 || n % cols == 0) { + rects[0].x = 0; + rects[0].y = top_y_coord(man); + rects[0].width = man->geometry.width; + rects[0].height = + num_visible_rows(n, cols) * man->geometry.boxheight; + if (man->shape.num_rects != 1 || + !rects_equal(rects, man->shape.rects)) { + man->dirty_flags |= SHAPE_CHANGED; + } + man->shape.num_rects = 1; + man->shape.rects[0] = rects[0]; + } else { + if (man->geometry.dir & GROW_DOWN) { + rects[0].x = 0; + rects[0].y = 0; + rects[0].width = man->geometry.width; + rects[0].height = (num_visible_rows(n, cols) - 1) * + man->geometry.boxheight; + rects[1].x = 0; + rects[1].y = rects[0].height; + rects[1].width = (n % cols) * man->geometry.boxwidth; + rects[1].height = man->geometry.boxheight; + } else { + rects[0].x = 0; + rects[0].y = top_y_coord(man); + rects[0].width = (n % cols) * man->geometry.boxwidth; + rects[0].height = man->geometry.boxheight; + rects[1].x = 0; + rects[1].y = rects[0].y + rects[0].height; + rects[1].width = man->geometry.width; + rects[1].height = (num_visible_rows(n, cols) - 1) * + man->geometry.boxheight; + } + if (man->shape.num_rects != 2 || + !rects_equal(rects, man->shape.rects) || + !rects_equal(rects + 1, man->shape.rects + 1)) { + man->dirty_flags |= SHAPE_CHANGED; + } + man->shape.num_rects = 2; + man->shape.rects[0] = rects[0]; + man->shape.rects[1] = rects[1]; + } #endif } -void set_manager_window_mapping (WinManager *man, int flag) +void +set_manager_window_mapping(WinManager *man, int flag) { - if (flag != man->window_mapped) { - man->window_mapped = flag; - man->dirty_flags |= MAPPING_CHANGED; - } + if (flag != man->window_mapped) { + man->window_mapped = flag; + man->dirty_flags |= MAPPING_CHANGED; + } } /***************************************************************************/ /* Major exported functions */ /***************************************************************************/ -void init_boxes (void) +void +init_boxes(void) { } -void init_button_array (ButtonArray *array) +void +init_button_array(ButtonArray *array) { - array->num_buttons = 0; - array->num_windows = 0; - array->buttons = NULL; + array->num_buttons = 0; + array->num_windows = 0; + array->buttons = NULL; } /* Pretty much like resize_manager, but used only to figure the correct size when creating the window */ -void size_manager (WinManager *man) +void +size_manager(WinManager *man) { - ManGeometry *new; - int oldwidth, oldheight, w, h; - - new = figure_geometry (man); - - assert (new->width && new->height); - - w = new->width; - h = new->height; + ManGeometry *new; + int oldwidth, oldheight, w, h; - oldwidth = man->geometry.width; - oldheight = man->geometry.height; + new = figure_geometry(man); - set_man_geometry (man, new); + assert(new->width && new->height); - if (oldheight != h || oldwidth != w) { - if (man->geometry.dir & GROW_UP) - man->geometry.y -= h - oldheight; - if (man->geometry.dir & GROW_LEFT) - man->geometry.x -= w - oldwidth; - } + w = new->width; + h = new->height; - ConsoleDebug (X11, "size_manager %s: %d %d %d %d\n", man->titlename, - man->geometry.x, man->geometry.y, man->geometry.width, - man->geometry.height); -} - -static void resize_manager (WinManager *man, int force) -{ - ManGeometry *new; - int oldwidth, oldheight, oldrows, oldcols; - int dir; + oldwidth = man->geometry.width; + oldheight = man->geometry.height; - if (man->can_draw == 0) - return; + set_man_geometry(man, new); - oldwidth = man->geometry.width; - oldheight = man->geometry.height; - oldrows = man->geometry.rows; - oldcols = man->geometry.cols; - dir = man->geometry.dir; + if (oldheight != h || oldwidth != w) { + if (man->geometry.dir & GROW_UP) + man->geometry.y -= h - oldheight; + if (man->geometry.dir & GROW_LEFT) + man->geometry.x -= w - oldwidth; + } - if (dir & GROW_FIXED) { - new = figure_geometry (man); - set_man_geometry (man, new); - set_shape (man); - if (force || oldrows != new->rows || oldcols != new->cols || - oldwidth != new->width || oldheight != new->height) { - man->dirty_flags |= GEOMETRY_CHANGED; - } - } - else { - new = figure_geometry (man); - set_man_geometry (man, new); - set_shape (man); - if (force || oldrows != new->rows || oldcols != new->cols || - oldwidth != new->width || oldheight != new->height) { - resize_window (man); - } - } + ConsoleDebug(X11, "size_manager %s: %d %d %d %d\n", man->titlename, + man->geometry.x, man->geometry.y, man->geometry.width, + man->geometry.height); +} + +static void +resize_manager(WinManager *man, int force) +{ + ManGeometry *new; + int oldwidth, oldheight, oldrows, oldcols; + int dir; + + if (man->can_draw == 0) + return; + + oldwidth = man->geometry.width; + oldheight = man->geometry.height; + oldrows = man->geometry.rows; + oldcols = man->geometry.cols; + dir = man->geometry.dir; + + if (dir & GROW_FIXED) { + new = figure_geometry(man); + set_man_geometry(man, new); + set_shape(man); + if (force || oldrows != new->rows || oldcols != new->cols || + oldwidth != new->width || oldheight != new->height) { + man->dirty_flags |= GEOMETRY_CHANGED; + } + } else { + new = figure_geometry(man); + set_man_geometry(man, new); + set_shape(man); + if (force || oldrows != new->rows || oldcols != new->cols || + oldwidth != new->width || oldheight != new->height) { + resize_window(man); + } + } } -static int center_padding (int h1, int h2) +static int +center_padding(int h1, int h2) { - return (h2 - h1) / 2; + return (h2 - h1) / 2; } -static void get_title_geometry (WinManager *man, ButtonGeometry *g) +static void +get_title_geometry(WinManager *man, ButtonGeometry *g) { - int text_pad; - assert (man); - g->button_x = 0; - g->button_y = 0; - g->button_w = man->geometry.boxwidth; - g->button_h = man->geometry.boxheight; - g->text_x = g->button_x + g->button_h / 2; - g->text_w = g->button_w - 4 - (g->text_x - g->button_x); - g->text_h = man->fontheight; - text_pad = center_padding (man->fontheight, g->button_h); + int text_pad; + assert(man); + g->button_x = 0; + g->button_y = 0; + g->button_w = man->geometry.boxwidth; + g->button_h = man->geometry.boxheight; + g->text_x = g->button_x + g->button_h / 2; + g->text_w = g->button_w - 4 - (g->text_x - g->button_x); + g->text_h = man->fontheight; + text_pad = center_padding(man->fontheight, g->button_h); - g->text_y = g->button_y + text_pad; - g->text_base = g->text_y + man->ButtonFont->ascent; + g->text_y = g->button_y + text_pad; + g->text_base = g->text_y + man->ButtonFont->ascent; } -static void get_button_geometry (WinManager *man, Button *button, - ButtonGeometry *g) +static void +get_button_geometry(WinManager *man, Button *button, ButtonGeometry *g) { - int icon_pad, text_pad; - WinData *win; + int icon_pad, text_pad; + WinData *win; - assert (man); + assert(man); - win = button->drawn_state.win; + win = button->drawn_state.win; - g->button_x = button->x; - g->button_y = button->y; + g->button_x = button->x; + g->button_y = button->y; - g->button_w = button->w; - g->button_h = button->h; + g->button_w = button->w; + g->button_h = button->h; /* [BV 16-Apr-97] Mini Icons work on black-and-white too */ #ifdef MINI_ICONS - if (man->draw_icons && win && win->pic.picture) { - /* If no window, then icon_* aren't used, so doesn't matter what - they are */ - g->icon_w = min (win->pic.width, g->button_h); - g->icon_h = min (g->button_h - 4, win->pic.height); - icon_pad = center_padding (g->icon_h, g->button_h); - g->icon_x = g->button_x + 4; - g->icon_y = g->button_y + icon_pad; - } - else { + if (man->draw_icons && win && win->pic.picture) { + /* If no window, then icon_* aren't used, so doesn't matter what + they are */ + g->icon_w = min(win->pic.width, g->button_h); + g->icon_h = min(g->button_h - 4, win->pic.height); + icon_pad = center_padding(g->icon_h, g->button_h); + g->icon_x = g->button_x + 4; + g->icon_y = g->button_y + icon_pad; + } else { #endif - g->icon_h = man->geometry.boxheight - 8; - g->icon_w = g->icon_h; + g->icon_h = man->geometry.boxheight - 8; + g->icon_w = g->icon_h; - icon_pad = center_padding (g->icon_h, g->button_h); - g->icon_x = g->button_x + icon_pad; - g->icon_y = g->button_y + icon_pad; + icon_pad = center_padding(g->icon_h, g->button_h); + g->icon_x = g->button_x + icon_pad; + g->icon_y = g->button_y + icon_pad; #ifdef MINI_ICONS - } + } #endif - g->text_x = g->icon_x + g->icon_w + 2; - g->text_w = g->button_w - 4 - (g->text_x - g->button_x); - g->text_h = man->fontheight; - - text_pad = center_padding (man->fontheight, g->button_h); - - g->text_y = g->button_y + text_pad; - g->text_base = g->text_y + man->ButtonFont->ascent; + g->text_x = g->icon_x + g->icon_w + 2; + g->text_w = g->button_w - 4 - (g->text_x - g->button_x); + g->text_h = man->fontheight; + + text_pad = center_padding(man->fontheight, g->button_h); + + g->text_y = g->button_y + text_pad; + g->text_base = g->text_y + man->ButtonFont->ascent; +} + +static void +draw_3d_square(WinManager *man, int x, int y, int w, int h, GC rgc, GC sgc) +{ + int i; + XSegment seg[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; + + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + 1; + + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + 1; + seg[i++].y2 = y + h - 2; + XDrawSegments(theDisplay, man->theWindow, rgc, 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; + + seg[i].x1 = x + w - 1; + seg[i].y1 = y; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + XDrawSegments(theDisplay, man->theWindow, sgc, seg, i); + + i = 0; + 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 - 2; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + + XDrawSegments(theDisplay, man->theWindow, sgc, seg, i); +} + +static void +draw_3d_icon(WinManager *man, int box, ButtonGeometry *g, int iconified, + int dir, Contexts contextId) +{ + if (iconified == 0) { + draw_3d_square(man, g->icon_x, g->icon_y, g->icon_w, g->icon_h, + man->flatContext[contextId], man->flatContext[contextId]); + } else { + if (dir == 1) { + draw_3d_square(man, g->icon_x, g->icon_y, g->icon_w, + g->icon_h, man->reliefContext[contextId], + man->shadowContext[contextId]); + } else { + draw_3d_square(man, g->icon_x, g->icon_y, g->icon_w, + g->icon_h, man->shadowContext[contextId], + man->reliefContext[contextId]); + } + } } -static void draw_3d_square (WinManager *man, int x, int y, int w, int h, - GC rgc, GC sgc) +/* this routine should only be called from draw_button() */ +static void +iconify_box(WinManager *man, WinData *win, int box, ButtonGeometry *g, + int iconified, Contexts contextId, int button_already_cleared) { - int i; - XSegment seg[4]; +#ifdef MINI_ICONS + XGCValues gcv; + unsigned long gcm; +#endif - i=0; - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = w+x-1; seg[i++].y2 = y; + if (!man->window_up) + return; - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = x; seg[i++].y2 = h+y-1; +/* [BV 16-Apr-97] Mini Icons work on black-and-white too */ +#ifdef MINI_ICONS + if (man->draw_icons && win->pic.picture) { + if (iconified == 0 && man->draw_icons != 2) { + if (!button_already_cleared) { + XFillRectangle(theDisplay, man->theWindow, + man->backContext[contextId], g->icon_x, + g->icon_y, g->icon_w, g->icon_h); + } + } else { + gcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; + gcv.clip_mask = win->pic.mask; + gcv.clip_x_origin = g->icon_x; + gcv.clip_y_origin = g->icon_y; + XChangeGC( + theDisplay, man->hiContext[contextId], gcm, &gcv); + + XCopyArea(theDisplay, win->pic.picture, man->theWindow, + man->hiContext[contextId], 0, 0, g->icon_w, + g->icon_h, g->icon_x, g->icon_y); + gcm = GCClipMask; + gcv.clip_mask = None; + XChangeGC( + theDisplay, man->hiContext[contextId], gcm, &gcv); + } + } else { +#endif + if (theDepth > 2) { + draw_3d_icon(man, box, g, iconified, 1, contextId); + } else { + if (iconified == 0) { + XFillArc(theDisplay, man->theWindow, + man->backContext[contextId], g->icon_x, + g->icon_y, g->icon_w, g->icon_h, 0, + 360 * 64); + } else { + XFillArc(theDisplay, man->theWindow, + man->hiContext[contextId], g->icon_x, + g->icon_y, g->icon_w, g->icon_h, 0, + 360 * 64); + } + } +#ifdef MINI_ICONS + } +#endif +} - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+1; +int +change_windows_manager(WinData *win) +{ + WinManager *oldman; + WinManager *newman; - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+1; seg[i++].y2 = y+h-2; - XDrawSegments(theDisplay, man->theWindow, rgc, seg, i); + ConsoleDebug(X11, "change_windows_manager: %s\n", win->titlename); - i=0; - seg[i].x1 = x; seg[i].y1 = y+h-1; - seg[i].x2 = w+x-1; seg[i++].y2 = y+h-1; + oldman = win->manager; + newman = figure_win_manager(win, ALL_NAME); + if (oldman && newman != oldman && win->button) { + delete_windows_button(win); + } + win->manager = newman; + set_win_displaystring(win); + check_win_complete(win); + check_in_window(win); + ConsoleDebug( + X11, "change_windows_manager: returning %d\n", newman != oldman); + return (newman != oldman); +} + +void +check_in_window(WinData *win) +{ + int in_viewport; + + if (win->manager && win->complete && + !(win->manager->usewinlist && (win->fvwm_flags & WINDOWLISTSKIP))) { + in_viewport = win_in_viewport(win); + if (win->button == NULL && in_viewport) { + insert_windows_button(win); + if (win->manager->window_up == 0 && + globals.got_window_list) + create_manager_window(win->manager->index); + } else if (win->button && !in_viewport) { + delete_windows_button(win); + } + } +} - seg[i].x1 = x+w-1; seg[i].y1 = y; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - XDrawSegments(theDisplay, man->theWindow, sgc, seg, i); +static void +get_gcs(WinManager *man, int state, GC *context1, GC *context2) +{ + switch (man->buttonState[state]) { + case BUTTON_FLAT: + *context1 = man->flatContext[state]; + *context2 = man->flatContext[state]; + break; - i=0; - seg[i].x1 = x+1; seg[i].y1 = y+h-2; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; + case BUTTON_UP: + case BUTTON_EDGEUP: + *context1 = man->reliefContext[state]; + *context2 = man->shadowContext[state]; + break; - seg[i].x1 = x+w-2; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; + case BUTTON_DOWN: + case BUTTON_EDGEDOWN: + *context1 = man->shadowContext[state]; + *context2 = man->reliefContext[state]; + break; - XDrawSegments(theDisplay, man->theWindow, sgc, seg, i); + default: + ConsoleMessage("Internal error in draw_button\n"); + break; + } } -static void draw_3d_icon (WinManager *man, int box, ButtonGeometry *g, - int iconified, int dir, Contexts contextId) +static void +draw_relief(WinManager *man, int button_state, ButtonGeometry *g, GC context1, + GC context2) { - if (iconified == 0) { - draw_3d_square (man, g->icon_x, g->icon_y, g->icon_w, g->icon_h, - man->flatContext[contextId], - man->flatContext[contextId]); - } - else { - if (dir == 1) { - draw_3d_square (man, g->icon_x, g->icon_y, g->icon_w, g->icon_h, - man->reliefContext[contextId], - man->shadowContext[contextId]); - } - else { - draw_3d_square (man, g->icon_x, g->icon_y, g->icon_w, g->icon_h, - man->shadowContext[contextId], - man->reliefContext[contextId]); - } - } -} + int state; + state = man->buttonState[button_state]; + if (state == BUTTON_EDGEUP || state == BUTTON_EDGEDOWN) { + draw_3d_square(man, g->button_x, g->button_y, g->button_w, + g->button_h, context1, context2); + draw_3d_square(man, g->button_x + 2, g->button_y + 2, + g->button_w - 4, g->button_h - 4, context2, context1); + } else { + draw_3d_square(man, g->button_x, g->button_y, g->button_w, + g->button_h, context1, context2); + } +} - /* this routine should only be called from draw_button() */ -static void iconify_box (WinManager *man, WinData *win, int box, - ButtonGeometry *g, int iconified, - Contexts contextId, int button_already_cleared) +static void +draw_button(WinManager *man, int button, int force) { -#ifdef MINI_ICONS - XGCValues gcv; - unsigned long gcm; -#endif + Button *b; + WinData *win; + ButtonGeometry g, old_g; + GC context1, context2; + Contexts button_state; + int cleared_button = 0, dirty; + int draw_background = 0, draw_icon = 0, draw_string = 0, + clear_old_pic = 0; - if (!man->window_up) - return; + assert(man); -/* [BV 16-Apr-97] Mini Icons work on black-and-white too */ -#ifdef MINI_ICONS - if (man->draw_icons && win->pic.picture) { - if (iconified == 0 && man->draw_icons != 2) { - if (!button_already_cleared) { - XFillRectangle (theDisplay, man->theWindow, - man->backContext[contextId], g->icon_x, g->icon_y, - g->icon_w, g->icon_h); - } - } - else { - gcm = GCClipMask|GCClipXOrigin|GCClipYOrigin; - gcv.clip_mask = win->pic.mask; - gcv.clip_x_origin = g->icon_x; - gcv.clip_y_origin = g->icon_y; - XChangeGC (theDisplay, man->hiContext[contextId], gcm, &gcv); - - XCopyArea(theDisplay, win->pic.picture, man->theWindow, - man->hiContext[contextId], 0, 0, g->icon_w, g->icon_h, - g->icon_x, g->icon_y); - gcm = GCClipMask; - gcv.clip_mask = None; - XChangeGC(theDisplay, man->hiContext[contextId], gcm, &gcv); - } - } - else { -#endif - if (theDepth > 2) { - draw_3d_icon (man, box, g, iconified, 1, contextId); - } - else { - if (iconified == 0) { - XFillArc (theDisplay, man->theWindow, man->backContext[contextId], - g->icon_x, g->icon_y, g->icon_w, g->icon_h, 0, 360 * 64); - } - else { - XFillArc (theDisplay, man->theWindow, man->hiContext[contextId], - g->icon_x, g->icon_y, g->icon_w, g->icon_h, 0, 360 * 64); - } - } + if (!man->window_up) { + ConsoleMessage("draw_button: manager not up yet\n"); + return; + } + + b = man->buttons.buttons[button]; + win = b->drawn_state.win; + dirty = b->drawn_state.dirty_flags; + + if (win && win->button != b) { + ConsoleMessage("Internal error in draw_button.\n"); + return; + } + + if (!win) { + return; + } + + if (force || (dirty & REDRAW_BUTTON)) { + ConsoleDebug(X11, "draw_button: %d forced\n", b->index); + draw_background = 1; + draw_icon = 1; + draw_string = 1; + } + /* figure out what we have to draw */ + if (dirty) { + ConsoleDebug(X11, "draw_button: %d dirty\n", b->index); + if (win) { + if (dirty & GEOMETRY_CHANGED) { + ConsoleDebug(X11, "\tGeometry changed\n"); + /* Determine if geometry has changed relative to + the window gravity */ + if (b->w != b->drawn_state.w || + b->h != b->drawn_state.h || + b->x - man->geometry.gravity_x != + b->drawn_state.x - + man->drawn_geometry.gravity_x || + b->y - man->geometry.gravity_y != + b->drawn_state.y - + man->drawn_geometry.gravity_y) { + draw_background = 1; + draw_icon = 1; + draw_string = 1; + } + } + if (dirty & STATE_CHANGED) { + ConsoleDebug(X11, "\tState changed\n"); + b->drawn_state.state = win->state; + draw_background = 1; + draw_icon = 1; + draw_string = 1; + } #ifdef MINI_ICONS - } + if (dirty & PICTURE_CHANGED) { + ConsoleDebug(X11, "\tPicture changed\n"); + get_button_geometry(man, b, &old_g); + b->drawn_state.pic = win->pic; + draw_icon = 1; + draw_string = 1; + clear_old_pic = 1; + } #endif + if ((dirty & ICON_STATE_CHANGED) && + b->drawn_state.iconified != win->iconified) { + ConsoleDebug(X11, "\tIcon changed\n"); + b->drawn_state.iconified = win->iconified; + draw_icon = 1; + } + if (dirty & STRING_CHANGED) { + ConsoleDebug(X11, "\tString changed: %s\n", + win->display_string); + b->drawn_state.display_string = + win->display_string; + assert(b->drawn_state.display_string); + draw_string = 1; + } + } + } + + if (win && (draw_background || draw_icon || draw_string)) { + get_button_geometry(man, b, &g); + ConsoleDebug(X11, "\tgeometry: %d %d %d %d\n", g.button_x, + g.button_y, g.button_w, g.button_h); + button_state = b->drawn_state.state; + if (draw_background) { + ConsoleDebug(X11, "\tDrawing background\n"); + XFillRectangle(theDisplay, man->theWindow, + man->backContext[button_state], g.button_x, + g.button_y, g.button_w, g.button_h); + cleared_button = 1; + + if (theDepth > 2) { + get_gcs( + man, button_state, &context1, &context2); + draw_relief( + man, button_state, &g, context1, context2); + } else if (button_state & SELECT_CONTEXT) { + XDrawRectangle(theDisplay, man->theWindow, + man->hiContext[button_state], + g.button_x + 2, g.button_y + 1, + g.button_w - 4, g.button_h - 2); + } + } + if (clear_old_pic) { + ConsoleDebug(X11, "\tClearing old picture\n"); + if (!cleared_button) { + XFillRectangle(theDisplay, man->theWindow, + man->backContext[PLAIN_CONTEXT], + old_g.icon_x, old_g.icon_y, + old_g.icon_w + 2, old_g.icon_h); + } + } + if (draw_icon) { + ConsoleDebug(X11, "\tDrawing icon\n"); + iconify_box(man, win, button, &g, win->iconified, + button_state, cleared_button); + } + if (draw_string) { + ConsoleDebug(X11, "\tDrawing text: %s\n", + b->drawn_state.display_string); + ClipRectangle(man, button_state, g.text_x, g.text_y, + g.text_w, g.text_h); + if (!cleared_button) { + XFillRectangle(theDisplay, man->theWindow, + man->backContext[button_state], g.text_x, + g.text_y, g.text_w, g.text_h); + } + XDrawString(theDisplay, man->theWindow, + man->hiContext[button_state], g.text_x, g.text_base, + b->drawn_state.display_string, + strlen(b->drawn_state.display_string)); + XSetClipMask( + theDisplay, man->hiContext[button_state], None); + } + } + + b->drawn_state.dirty_flags = 0; + b->drawn_state.x = b->x; + b->drawn_state.y = b->y; + b->drawn_state.w = b->w; + b->drawn_state.h = b->h; + XFlush(theDisplay); +} +void +draw_managers(void) +{ + int i; + for (i = 0; i < globals.num_managers; i++) + draw_manager(&globals.managers[i]); } -int change_windows_manager (WinData *win) +static void +draw_empty_manager(WinManager *man) { - WinManager *oldman; - WinManager *newman; + GC context1, context2; + int state = TITLE_CONTEXT; + ButtonGeometry g; - ConsoleDebug (X11, "change_windows_manager: %s\n", win->titlename); + ConsoleDebug(X11, "draw_empty_manager\n"); + get_title_geometry(man, &g); - oldman = win->manager; - newman = figure_win_manager (win, ALL_NAME); - if (oldman && newman != oldman && win->button) { - delete_windows_button (win); - } - win->manager = newman; - set_win_displaystring (win); - check_win_complete (win); - check_in_window (win); - ConsoleDebug (X11, "change_windows_manager: returning %d\n", - newman != oldman); - return (newman != oldman); -} - -void check_in_window (WinData *win) -{ - int in_viewport; - - if (win->manager && win->complete && - !(win->manager->usewinlist && (win->fvwm_flags & WINDOWLISTSKIP))) { - in_viewport = win_in_viewport (win); - if (win->button == NULL && in_viewport) { - insert_windows_button (win); - if (win->manager->window_up == 0 && globals.got_window_list) - create_manager_window (win->manager->index); - } - else if (win->button && !in_viewport) { - delete_windows_button (win); - } - } -} - -static void get_gcs (WinManager *man, int state, GC *context1, GC *context2) -{ - switch (man->buttonState[state]) { - case BUTTON_FLAT: - *context1 = man->flatContext[state]; - *context2 = man->flatContext[state]; - break; - - case BUTTON_UP: - case BUTTON_EDGEUP: - *context1 = man->reliefContext[state]; - *context2 = man->shadowContext[state]; - break; - - case BUTTON_DOWN: - case BUTTON_EDGEDOWN: - *context1 = man->shadowContext[state]; - *context2 = man->reliefContext[state]; - break; - - default: - ConsoleMessage ("Internal error in draw_button\n"); - break; - } -} - -static void draw_relief (WinManager *man, int button_state, ButtonGeometry *g, - GC context1, GC context2) -{ - int state; - state = man->buttonState[button_state]; - - if (state == BUTTON_EDGEUP || state == BUTTON_EDGEDOWN) { - draw_3d_square (man, g->button_x, g->button_y, g->button_w, g->button_h, - context1, context2); - draw_3d_square (man, g->button_x + 2, g->button_y + 2, g->button_w - 4, - g->button_h - 4, context2, context1); - } - else { - draw_3d_square (man, g->button_x, g->button_y, g->button_w, g->button_h, - context1, context2); - } -} - -static void draw_button (WinManager *man, int button, int force) -{ - Button *b; - WinData *win; - ButtonGeometry g, old_g; - GC context1, context2; - Contexts button_state; - int cleared_button = 0, dirty; - int draw_background = 0, draw_icon = 0, draw_string = 0, clear_old_pic = 0; - - assert (man); - - if (!man->window_up) { - ConsoleMessage ("draw_button: manager not up yet\n"); - return; - } - - b = man->buttons.buttons[button]; - win = b->drawn_state.win; - dirty = b->drawn_state.dirty_flags; - - if (win && win->button != b) { - ConsoleMessage ("Internal error in draw_button.\n"); - return; - } - - if (!win) { - return; - } - - if (force || (dirty & REDRAW_BUTTON)) { - ConsoleDebug (X11, "draw_button: %d forced\n", b->index); - draw_background = 1; - draw_icon = 1; - draw_string = 1; - } - /* figure out what we have to draw */ - if (dirty) { - ConsoleDebug (X11, "draw_button: %d dirty\n", b->index); - if (win) { - if (dirty & GEOMETRY_CHANGED) { - ConsoleDebug (X11, "\tGeometry changed\n"); - /* Determine if geometry has changed relative to the - window gravity */ - if (b->w != b->drawn_state.w || b->h != b->drawn_state.h || - b->x - man->geometry.gravity_x != - b->drawn_state.x - man->drawn_geometry.gravity_x || - b->y - man->geometry.gravity_y != - b->drawn_state.y - man->drawn_geometry.gravity_y) { - draw_background = 1; - draw_icon = 1; - draw_string = 1; + XFillRectangle(theDisplay, man->theWindow, man->backContext[state], + g.button_x, g.button_y, g.button_w, g.button_h); + if (theDepth > 2) { + get_gcs(man, state, &context1, &context2); + draw_relief(man, state, &g, context1, context2); + } else { + } + ClipRectangle(man, state, g.text_x, g.text_y, g.text_w, g.text_h); + XDrawString(theDisplay, man->theWindow, man->hiContext[state], g.text_x, + g.text_base, man->titlename, strlen(man->titlename)); + XSetClipMask(theDisplay, man->hiContext[state], None); +} + +void +draw_manager(WinManager *man) +{ + int i, force_draw = 0, update_geometry = 0, redraw_all = 0; + int shape_changed = 0; + + assert(man->buttons.num_buttons >= 0 && man->buttons.num_windows >= 0); + + if (!man->window_up) + return; + + ConsoleDebug(X11, "Drawing Manager: %s\n", man->titlename); + redraw_all = man->dirty_flags & REDRAW_MANAGER; + + if (redraw_all || (man->buttons.dirty_flags & NUM_WINDOWS_CHANGED)) { + ConsoleDebug(X11, "\tresizing manager\n"); + resize_manager(man, redraw_all); + clear_empty_region(man); + update_geometry = 1; + force_draw = 1; + } + + if (redraw_all || (man->dirty_flags & MAPPING_CHANGED)) { + force_draw = 1; + ConsoleDebug( + X11, "manager %s: mapping changed\n", man->titlename); } - } - if (dirty & STATE_CHANGED) { - ConsoleDebug (X11, "\tState changed\n"); - b->drawn_state.state = win->state; - draw_background = 1; - draw_icon = 1; - draw_string = 1; - } -#ifdef MINI_ICONS - if (dirty & PICTURE_CHANGED) { - ConsoleDebug (X11, "\tPicture changed\n"); - get_button_geometry (man, b, &old_g); - b->drawn_state.pic = win->pic; - draw_icon = 1; - draw_string = 1; - clear_old_pic = 1; - } -#endif - if ((dirty & ICON_STATE_CHANGED) && - b->drawn_state.iconified != win->iconified) { - ConsoleDebug (X11, "\tIcon changed\n"); - b->drawn_state.iconified = win->iconified; - draw_icon = 1; - } - if (dirty & STRING_CHANGED) { - ConsoleDebug (X11, "\tString changed: %s\n", win->display_string); - b->drawn_state.display_string = win->display_string; - assert (b->drawn_state.display_string); - draw_string = 1; - } - } - } - - if (win && (draw_background || draw_icon || draw_string)) { - get_button_geometry (man, b, &g); - ConsoleDebug (X11, "\tgeometry: %d %d %d %d\n", g.button_x, g.button_y, - g.button_w, g.button_h); - button_state = b->drawn_state.state; - if (draw_background) { - ConsoleDebug (X11, "\tDrawing background\n"); - XFillRectangle (theDisplay, man->theWindow, - man->backContext[button_state], g.button_x, - g.button_y, g.button_w, g.button_h); - cleared_button = 1; - - if (theDepth > 2) { - get_gcs (man, button_state, &context1, &context2); - draw_relief (man, button_state, &g, context1, context2); - } - else if (button_state & SELECT_CONTEXT) { - XDrawRectangle (theDisplay, man->theWindow, - man->hiContext[button_state], - g.button_x + 2, g.button_y + 1, - g.button_w - 4, g.button_h - 2); - } - } - if (clear_old_pic) { - ConsoleDebug (X11, "\tClearing old picture\n"); - if (!cleared_button) { - XFillRectangle (theDisplay, man->theWindow, - man->backContext[PLAIN_CONTEXT], - old_g.icon_x, old_g.icon_y, - old_g.icon_w + 2, old_g.icon_h); - } - } - if (draw_icon) { - ConsoleDebug (X11, "\tDrawing icon\n"); - iconify_box (man, win, button, &g, win->iconified, button_state, - cleared_button); - } - if (draw_string) { - ConsoleDebug (X11, "\tDrawing text: %s\n", - b->drawn_state.display_string); - ClipRectangle (man, button_state, g.text_x, g.text_y, g.text_w, - g.text_h); - if (!cleared_button) { - XFillRectangle (theDisplay, man->theWindow, - man->backContext[button_state], - g.text_x, g.text_y, g.text_w, g.text_h); - } - XDrawString (theDisplay, man->theWindow, - man->hiContext[button_state], - g.text_x, g.text_base, b->drawn_state.display_string, - strlen (b->drawn_state.display_string)); - XSetClipMask (theDisplay, man->hiContext[button_state], None); - } - } - - b->drawn_state.dirty_flags = 0; - b->drawn_state.x = b->x; - b->drawn_state.y = b->y; - b->drawn_state.w = b->w; - b->drawn_state.h = b->h; - XFlush (theDisplay); -} - -void draw_managers (void) -{ - int i; - for (i = 0; i < globals.num_managers; i++) - draw_manager (&globals.managers[i]); -} - -static void draw_empty_manager (WinManager *man) -{ - GC context1, context2; - int state = TITLE_CONTEXT; - ButtonGeometry g; - - ConsoleDebug (X11, "draw_empty_manager\n"); - get_title_geometry (man, &g); - - XFillRectangle (theDisplay, man->theWindow, man->backContext[state], - g.button_x, g.button_y, g.button_w, g.button_h); - if (theDepth > 2) { - get_gcs (man, state, &context1, &context2); - draw_relief (man, state, &g, context1, context2); - } - else { - } - ClipRectangle (man, state, g.text_x, g.text_y, g.text_w, g.text_h); - XDrawString (theDisplay, man->theWindow, man->hiContext[state], - g.text_x, g.text_base, man->titlename, strlen (man->titlename)); - XSetClipMask (theDisplay, man->hiContext[state], None); -} - -void draw_manager (WinManager *man) -{ - int i, force_draw = 0, update_geometry = 0, redraw_all = 0; - int shape_changed = 0; - - assert (man->buttons.num_buttons >= 0 && man->buttons.num_windows >= 0); - - if (!man->window_up) - return; - - ConsoleDebug (X11, "Drawing Manager: %s\n", man->titlename); - redraw_all = man->dirty_flags & REDRAW_MANAGER; - - if (redraw_all || (man->buttons.dirty_flags & NUM_WINDOWS_CHANGED)) { - ConsoleDebug (X11, "\tresizing manager\n"); - resize_manager (man, redraw_all); - clear_empty_region (man); - update_geometry = 1; - force_draw = 1; - } - - - if (redraw_all || (man->dirty_flags & MAPPING_CHANGED)) { - force_draw = 1; - ConsoleDebug (X11, "manager %s: mapping changed\n", man->titlename); - } #ifdef SHAPE - if (man->shaped && (redraw_all || (man->dirty_flags & SHAPE_CHANGED) )){ - /* This little piggie waits until past resize requests get processed */ - XSync (theDisplay, False); - XShapeCombineRectangles (theDisplay, man->theWindow, ShapeBounding, - 0, 0, man->shape.rects, man->shape.num_rects, - ShapeSet, Unsorted); - XShapeCombineRectangles (theDisplay, man->theWindow, ShapeClip, - 0, 0, man->shape.rects, man->shape.num_rects, - ShapeSet, Unsorted); - shape_changed = 1; - update_geometry = 1; - /* And this little piggie waits for shape to get processed before - drawing buttons */ - XSync (theDisplay, False); - } + if (man->shaped && (redraw_all || (man->dirty_flags & SHAPE_CHANGED))) { + /* This little piggie waits until past resize requests get + * processed */ + XSync(theDisplay, False); + XShapeCombineRectangles(theDisplay, man->theWindow, + ShapeBounding, 0, 0, man->shape.rects, man->shape.num_rects, + ShapeSet, Unsorted); + XShapeCombineRectangles(theDisplay, man->theWindow, ShapeClip, + 0, 0, man->shape.rects, man->shape.num_rects, ShapeSet, + Unsorted); + shape_changed = 1; + update_geometry = 1; + /* And this little piggie waits for shape to get processed + before drawing buttons */ + XSync(theDisplay, False); + } #endif - if (redraw_all || (man->dirty_flags & GEOMETRY_CHANGED)) { - ConsoleDebug (X11, "\tredrawing all buttons\n"); - update_geometry = 1; - } - - if (update_geometry) { - for (i = 0; i < man->buttons.num_windows; i++) - set_button_geometry (man, man->buttons.buttons[i]); - } - - man->dirty_flags = 0; - man->buttons.dirty_flags = 0; - man->buttons.drawn_num_buttons = man->buttons.num_buttons; - man->buttons.drawn_num_windows = man->buttons.num_windows; - - if (man->buttons.num_windows == 0) { - if (force_draw) - draw_empty_manager (man); - } - else { - /* I was having the problem where when the shape changed the manager - wouldn't get redrawn. It appears we weren't getting the expose. - How can I tell when I am going to reliably get an expose event? */ - - if (1 || !shape_changed) { - /* if shape changed, we'll catch it on the expose */ - for (i = 0; i < man->buttons.num_buttons; i++) { - draw_button (man, i, force_draw); - } - } - } - man->drawn_geometry = man->geometry; - XFlush (theDisplay); -} - - -static int compare_windows(SortType type, WinData *a, WinData *b) -{ - if (type == SortId) { - return a->app_id - b->app_id; - } - else if (type == SortName) { - return strcasecmp (a->display_string, b->display_string); - } - else if (type == SortNameCase) { - return strcmp (a->display_string, b->display_string); - } - else { - ConsoleMessage ("Internal error in compare_windows\n"); - return 0; - } + if (redraw_all || (man->dirty_flags & GEOMETRY_CHANGED)) { + ConsoleDebug(X11, "\tredrawing all buttons\n"); + update_geometry = 1; + } + + if (update_geometry) { + for (i = 0; i < man->buttons.num_windows; i++) + set_button_geometry(man, man->buttons.buttons[i]); + } + + man->dirty_flags = 0; + man->buttons.dirty_flags = 0; + man->buttons.drawn_num_buttons = man->buttons.num_buttons; + man->buttons.drawn_num_windows = man->buttons.num_windows; + + if (man->buttons.num_windows == 0) { + if (force_draw) + draw_empty_manager(man); + } else { + /* I was having the problem where when the shape changed the + manager wouldn't get redrawn. It appears we weren't getting + the expose. How can I tell when I am going to reliably get an + expose event? */ + + if (1 || !shape_changed) { + /* if shape changed, we'll catch it on the expose */ + for (i = 0; i < man->buttons.num_buttons; i++) { + draw_button(man, i, force_draw); + } + } + } + man->drawn_geometry = man->geometry; + XFlush(theDisplay); +} + +static int +compare_windows(SortType type, WinData *a, WinData *b) +{ + if (type == SortId) { + return a->app_id - b->app_id; + } else if (type == SortName) { + return strcasecmp(a->display_string, b->display_string); + } else if (type == SortNameCase) { + return strcmp(a->display_string, b->display_string); + } else { + ConsoleMessage("Internal error in compare_windows\n"); + return 0; + } } /* find_windows_spot: returns index of button to stick the window in. @@ -1453,351 +1520,366 @@ static int compare_windows(SortType type, WinData *a, WinData *b) * if it were. */ -static int find_windows_spot (WinData *win) -{ - WinManager *man = win->manager; - int num_windows = man->buttons.num_windows; - - if (man->sort != SortNone) { - int i, cur, start, finish, cmp_dir, correction; - Button **bp; - - bp = man->buttons.buttons; - if (win->button) { - /* start search from our current location */ - cur = win->button->index; - - if (cur - 1 >= 0 && - compare_windows (man->sort, - win, bp[cur - 1]->drawn_state.win) < 0) { - start = cur - 1; - finish = -1; - cmp_dir = -1; - correction = 1; - } - else if (cur < num_windows - 1 && - compare_windows (man->sort, - win, bp[cur + 1]->drawn_state.win) > 0) { - start = cur + 1; - finish = num_windows; - cmp_dir = 1; - correction = -1; - } - else { - return cur; - } - } - else { - start = 0; - finish = num_windows; - cmp_dir = 1; - correction = 0; - } - for (i = start; i != finish && bp[i]->drawn_state.win && cmp_dir * - compare_windows (man->sort, win, bp[i]->drawn_state.win) > 0; - i = i + cmp_dir) - ; - i += correction; - ConsoleDebug (X11, "find_windows_spot: %s %d\n", win->display_string, i); - return i; - } - else { - if (win->button) { - /* already have a perfectly fine spot */ - return win->button->index; - } - else { - return num_windows; - } - } - - /* shouldn't get here */ - return -1; -} - -static void move_window_buttons (WinManager *man, int start, int finish, - int offset) -{ - int n = man->buttons.num_buttons, i; - Button **bp; - - ConsoleDebug (X11, "move_window_buttons: %s(%d): (%d, %d) + %d\n", - man->titlename, n, start, finish, offset); - - if (finish >= n || finish + offset >= n || start < 0 || start + offset < 0) { - ConsoleMessage ("Internal error in move_window_buttons\n"); - ConsoleMessage ("\tn = %d, start = %d, finish = %d, offset = %d\n", - n, start, finish, offset); - return; - } - - bp = man->buttons.buttons; - - if (offset > 0) { - for (i = finish; i >= start; i--) { - if (bp[i]->drawn_state.win) - bp[i]->drawn_state.win->button = bp[i + offset]; - bp[i + offset]->drawn_state = bp[i]->drawn_state; - bp[i + offset]->drawn_state.dirty_flags = ALL_CHANGED; - } - } - else if (offset < 0) { - for (i = start; i <= finish; i++) { - if (bp[i]->drawn_state.win) - bp[i]->drawn_state.win->button = bp[i + offset]; - bp[i + offset]->drawn_state = bp[i]->drawn_state; - bp[i + offset]->drawn_state.dirty_flags = ALL_CHANGED; - } - } -} - -static void insert_windows_button (WinData *win) -{ - int spot; - int selected_index = -1; - WinManager *man = win->manager; - ButtonArray *buttons; - - ConsoleDebug (X11, "insert_windows_button: %s\n", win->titlename); - - assert (man); - selected_index = selected_button_in_man (man); - - if (win->button) { - ConsoleDebug (X11, "insert_windows_button: POSSIBLE BUG: " - "already have a button\n"); - return; - } - - if (!win || !win->complete || !man) { - ConsoleMessage ("Internal error in insert_windows_button\n"); - ShutMeDown (1); - } - - buttons = &man->buttons; - - spot = find_windows_spot (win); - - increase_num_windows (buttons, 1); - move_window_buttons (man, spot, buttons->num_windows - 2, 1); - - set_window_button (win, spot); - if (selected_index >= 0) { - ConsoleDebug (X11, "insert_windows_button: selected_index = %d, moving\n", - selected_index); - move_highlight (man, man->buttons.buttons[selected_index]); - } -} - -void delete_windows_button (WinData *win) +static int +find_windows_spot(WinData *win) +{ + WinManager *man = win->manager; + int num_windows = man->buttons.num_windows; + + if (man->sort != SortNone) { + int i, cur, start, finish, cmp_dir, correction; + Button **bp; + + bp = man->buttons.buttons; + if (win->button) { + /* start search from our current location */ + cur = win->button->index; + + if (cur - 1 >= 0 && + compare_windows(man->sort, win, + bp[cur - 1]->drawn_state.win) < 0) { + start = cur - 1; + finish = -1; + cmp_dir = -1; + correction = 1; + } else if (cur < num_windows - 1 && + compare_windows(man->sort, win, + bp[cur + 1]->drawn_state.win) > 0) { + start = cur + 1; + finish = num_windows; + cmp_dir = 1; + correction = -1; + } else { + return cur; + } + } else { + start = 0; + finish = num_windows; + cmp_dir = 1; + correction = 0; + } + for (i = start; i != finish && bp[i]->drawn_state.win && + cmp_dir * compare_windows(man->sort, win, + bp[i]->drawn_state.win) > + 0; + i = i + cmp_dir) + ; + i += correction; + ConsoleDebug( + X11, "find_windows_spot: %s %d\n", win->display_string, i); + return i; + } else { + if (win->button) { + /* already have a perfectly fine spot */ + return win->button->index; + } else { + return num_windows; + } + } + + /* shouldn't get here */ + return -1; +} + +static void +move_window_buttons(WinManager *man, int start, int finish, int offset) +{ + int n = man->buttons.num_buttons, i; + Button **bp; + + ConsoleDebug(X11, "move_window_buttons: %s(%d): (%d, %d) + %d\n", + man->titlename, n, start, finish, offset); + + if (finish >= n || finish + offset >= n || start < 0 || + start + offset < 0) { + ConsoleMessage("Internal error in move_window_buttons\n"); + ConsoleMessage( + "\tn = %d, start = %d, finish = %d, offset = %d\n", n, + start, finish, offset); + return; + } + + bp = man->buttons.buttons; + + if (offset > 0) { + for (i = finish; i >= start; i--) { + if (bp[i]->drawn_state.win) + bp[i]->drawn_state.win->button = bp[i + offset]; + bp[i + offset]->drawn_state = bp[i]->drawn_state; + bp[i + offset]->drawn_state.dirty_flags = ALL_CHANGED; + } + } else if (offset < 0) { + for (i = start; i <= finish; i++) { + if (bp[i]->drawn_state.win) + bp[i]->drawn_state.win->button = bp[i + offset]; + bp[i + offset]->drawn_state = bp[i]->drawn_state; + bp[i + offset]->drawn_state.dirty_flags = ALL_CHANGED; + } + } +} + +static void +insert_windows_button(WinData *win) { - int spot; - int selected_index = -1; - WinManager *man = (win->manager); - ButtonArray *buttons; + int spot; + int selected_index = -1; + WinManager *man = win->manager; + ButtonArray *buttons; - ConsoleDebug (X11, "delete_windows_button: %s\n", win->titlename); + ConsoleDebug(X11, "insert_windows_button: %s\n", win->titlename); - assert (man); + if (!win || !win->complete || !man) { + ConsoleMessage("Internal error in insert_windows_button\n"); + ShutMeDown(1); + } + + if (win->button) { + ConsoleDebug(X11, "insert_windows_button: POSSIBLE BUG: " + "already have a button\n"); + return; + } - buttons = &win->manager->buttons; + assert(man); + selected_index = selected_button_in_man(man); - assert (win->button); - assert (buttons->buttons); + buttons = &man->buttons; - selected_index = selected_button_in_man (man); - ConsoleDebug (X11, "delete_windows_button: selected_index = %d\n", - selected_index); + spot = find_windows_spot(win); - spot = win->button->index; + increase_num_windows(buttons, 1); + move_window_buttons(man, spot, buttons->num_windows - 2, 1); - move_window_buttons (win->manager, spot + 1, buttons->num_windows - 1, -1); - clear_button (buttons->buttons[buttons->num_windows - 1]); - increase_num_windows (buttons, -1); - win->button = NULL; - if (globals.focus_win == win) { - globals.focus_win = NULL; - } - if (selected_index >= 0) { - ConsoleDebug (X11, "delete_windows_button: selected_index = %d, moving\n", - selected_index); - move_highlight (man, man->buttons.buttons[selected_index]); - } - win->state = 0; + set_window_button(win, spot); + if (selected_index >= 0) { + ConsoleDebug(X11, + "insert_windows_button: selected_index = %d, moving\n", + selected_index); + move_highlight(man, man->buttons.buttons[selected_index]); + } } -void resort_windows_button (WinData *win) +void +delete_windows_button(WinData *win) { - int new_spot, cur_spot; - int selected_index = -1; - WinManager *man = win->manager; + int spot; + int selected_index = -1; + WinManager *man = (win->manager); + ButtonArray *buttons; - assert (win->button && man); + ConsoleDebug(X11, "delete_windows_button: %s\n", win->titlename); - ConsoleDebug (X11, "In resort_windows_button: %s\n", win->resname); + assert(man); - selected_index = selected_button_in_man (man); + buttons = &win->manager->buttons; - new_spot = find_windows_spot (win); - cur_spot = win->button->index; + assert(win->button); + assert(buttons->buttons); - print_button_info (win->button); + selected_index = selected_button_in_man(man); + ConsoleDebug(X11, "delete_windows_button: selected_index = %d\n", + selected_index); - if (new_spot != cur_spot) { - ConsoleDebug (X11, "resort_windows_button: win moves from %d to %d\n", - cur_spot, new_spot); - if (new_spot < cur_spot) { - move_window_buttons (man, new_spot, cur_spot - 1, +1); - } - else { - move_window_buttons (man, cur_spot + 1, new_spot, -1); - } - set_window_button (win, new_spot); + spot = win->button->index; - if (selected_index >= 0) { - move_highlight (man, man->buttons.buttons[selected_index]); - } - } + move_window_buttons( + win->manager, spot + 1, buttons->num_windows - 1, -1); + clear_button(buttons->buttons[buttons->num_windows - 1]); + increase_num_windows(buttons, -1); + win->button = NULL; + if (globals.focus_win == win) { + globals.focus_win = NULL; + } + if (selected_index >= 0) { + ConsoleDebug(X11, + "delete_windows_button: selected_index = %d, moving\n", + selected_index); + move_highlight(man, man->buttons.buttons[selected_index]); + } + win->state = 0; } -void move_highlight (WinManager *man, Button *b) +void +resort_windows_button(WinData *win) { - WinData *old; + int new_spot, cur_spot; + int selected_index = -1; + WinManager *man = win->manager; + + assert(win->button && man); - assert (man); + ConsoleDebug(X11, "In resort_windows_button: %s\n", win->resname); - ConsoleDebug (X11, "move_highlight\n"); + selected_index = selected_button_in_man(man); - old = globals.select_win; + new_spot = find_windows_spot(win); + cur_spot = win->button->index; - if (old && old->button) { - del_win_state (old, SELECT_CONTEXT); - old->manager->select_button = NULL; - draw_button (old->manager, old->button->index, 0); - } - if (b && b->drawn_state.win) { - add_win_state (b->drawn_state.win, SELECT_CONTEXT); - draw_button (man, b->index, 0); - globals.select_win = b->drawn_state.win; - } - else { - globals.select_win = NULL; - } + print_button_info(win->button); - man->select_button = b; + if (new_spot != cur_spot) { + ConsoleDebug(X11, + "resort_windows_button: win moves from %d to %d\n", + cur_spot, new_spot); + if (new_spot < cur_spot) { + move_window_buttons(man, new_spot, cur_spot - 1, +1); + } else { + move_window_buttons(man, cur_spot + 1, new_spot, -1); + } + set_window_button(win, new_spot); + + if (selected_index >= 0) { + move_highlight( + man, man->buttons.buttons[selected_index]); + } + } } -void man_exposed (WinManager *man, XEvent *theEvent) +void +move_highlight(WinManager *man, Button *b) { - int x1, y1, w1, h1; - int x2, y2, w2, h2; - int i; - Button **bp; + WinData *old; + + assert(man); + + ConsoleDebug(X11, "move_highlight\n"); + + old = globals.select_win; - ConsoleDebug (X11, "manager: %s, got expose\n", man->titlename); + if (old && old->button) { + del_win_state(old, SELECT_CONTEXT); + old->manager->select_button = NULL; + draw_button(old->manager, old->button->index, 0); + } + if (b && b->drawn_state.win) { + add_win_state(b->drawn_state.win, SELECT_CONTEXT); + draw_button(man, b->index, 0); + globals.select_win = b->drawn_state.win; + } else { + globals.select_win = NULL; + } - x1 = theEvent->xexpose.x; - y1 = theEvent->xexpose.y; - w1 = theEvent->xexpose.width; - h1 = theEvent->xexpose.height; + man->select_button = b; +} + +void +man_exposed(WinManager *man, XEvent *theEvent) +{ + int x1, y1, w1, h1; + int x2, y2, w2, h2; + int i; + Button **bp; - w2 = man->geometry.boxwidth; - h2 = man->geometry.boxheight; + ConsoleDebug(X11, "manager: %s, got expose\n", man->titlename); - bp = man->buttons.buttons; + x1 = theEvent->xexpose.x; + y1 = theEvent->xexpose.y; + w1 = theEvent->xexpose.width; + h1 = theEvent->xexpose.height; + + w2 = man->geometry.boxwidth; + h2 = man->geometry.boxheight; + + bp = man->buttons.buttons; #ifdef SHAPE - /* There's some weird problem where if we change window shapes, we can't - draw into buttons in the area NewShape intersect (not OldShape) until - we get our Expose event. So, for now, just redraw everything when we - get Expose events. This has the disadvantage of drawing buttons twice, - but avoids having to match which expose event results from which shape - change */ - - if (man->buttons.num_windows) { - for (i = 0; i < man->buttons.num_windows; i++) { - bp[i]->drawn_state.dirty_flags |= REDRAW_BUTTON; - } - } - else { - draw_empty_manager (man); - } - - return; + /* There's some weird problem where if we change window shapes, we can't + draw into buttons in the area NewShape intersect (not OldShape) until + we get our Expose event. So, for now, just redraw everything when we + get Expose events. This has the disadvantage of drawing buttons + twice, but avoids having to match which expose event results from + which shape change */ + + if (man->buttons.num_windows) { + for (i = 0; i < man->buttons.num_windows; i++) { + bp[i]->drawn_state.dirty_flags |= REDRAW_BUTTON; + } + } else { + draw_empty_manager(man); + } + + return; #endif - if (man->buttons.num_windows) { - for (i = 0; i < man->buttons.num_windows; i++) { - x2 = index_to_col (man, i) * w2; - y2 = index_to_row (man, i) * h2; - if (RECTANGLES_INTERSECT (x1, y1, w1, h1, x2, y2, w2, h2)) { - bp[i]->drawn_state.dirty_flags |= REDRAW_BUTTON; - } - } - } - else { - draw_empty_manager (man); - } + if (man->buttons.num_windows) { + for (i = 0; i < man->buttons.num_windows; i++) { + x2 = index_to_col(man, i) * w2; + y2 = index_to_row(man, i) * h2; + if (RECTANGLES_INTERSECT( + x1, y1, w1, h1, x2, y2, w2, h2)) { + bp[i]->drawn_state.dirty_flags |= REDRAW_BUTTON; + } + } + } else { + draw_empty_manager(man); + } } /***************************************************************************/ /* Debugging routines */ /***************************************************************************/ -void check_managers_consistency (void) +void +check_managers_consistency(void) { #ifdef PRINT_DEBUG - int i, j; - Button **b; - - for (i = 0; i < globals.num_managers; i++) { - for (j = 0, b = globals.managers[i].buttons.buttons; - j < globals.managers[i].buttons.num_buttons; j++, b++) { - if ((*b)->drawn_state.win && (*b)->drawn_state.win->button != *b) { - ConsoleMessage ("manager %d, button %d is confused\n", i, j); - abort (); - } - else if ((*b)->drawn_state.win && - j >= globals.managers[i].buttons.num_windows) { - ConsoleMessage ("manager %d: button %d has window and shouldn't\n", - i, j); - abort (); - } - } - } + int i, j; + Button **b; + + for (i = 0; i < globals.num_managers; i++) { + for (j = 0, b = globals.managers[i].buttons.buttons; + j < globals.managers[i].buttons.num_buttons; j++, b++) { + if ((*b)->drawn_state.win && + (*b)->drawn_state.win->button != *b) { + ConsoleMessage( + "manager %d, button %d is confused\n", i, + j); + abort(); + } else if ((*b)->drawn_state.win && + j >= globals.managers[i] + .buttons.num_windows) { + ConsoleMessage("manager %d: button %d has " + "window and shouldn't\n", + i, j); + abort(); + } + } + } #endif } -static void print_button_info (Button *b) +static void +print_button_info(Button *b) { #ifdef PRINT_DEBUG - ConsoleMessage ("button: %d\n", b->index); - ConsoleMessage ("win: 0x%x\n", b->drawn_state.win); - ConsoleMessage ("dirty: 0x%x\n", b->drawn_state.dirty_flags); - if (b->drawn_state.win) { - ConsoleMessage ("name: %s\n", b->drawn_state.display_string); - ConsoleMessage ("iconified: %d state %d\n", b->drawn_state.iconified, - b->drawn_state.state); - ConsoleMessage ("win->button: 0x%x\n", b->drawn_state.win->button); - } + ConsoleMessage("button: %d\n", b->index); + ConsoleMessage("win: 0x%x\n", b->drawn_state.win); + ConsoleMessage("dirty: 0x%x\n", b->drawn_state.dirty_flags); + if (b->drawn_state.win) { + ConsoleMessage("name: %s\n", b->drawn_state.display_string); + ConsoleMessage("iconified: %d state %d\n", + b->drawn_state.iconified, b->drawn_state.state); + ConsoleMessage( + "win->button: 0x%x\n", b->drawn_state.win->button); + } #endif } #ifdef PRINT_DEBUG -static void print_buttons (WinManager *man) +static void +print_buttons(WinManager *man) { - int i; - Button *b; + int i; + Button *b; - ConsoleMessage ("Buttons for manager: %s\n", man->titlename); + ConsoleMessage("Buttons for manager: %s\n", man->titlename); - for (i = 0; i < man->buttons.num_buttons; i++) { - b = man->buttons.buttons[i]; - ConsoleMessage ("Button: %d, index = %d\n", i, b->index); - ConsoleMessage ("\tdirty flags: 0x%x\n", b->drawn_state.dirty_flags); - ConsoleMessage ("\twin: 0x%x\n", b->drawn_state.win); - } + for (i = 0; i < man->buttons.num_buttons; i++) { + b = man->buttons.buttons[i]; + ConsoleMessage("Button: %d, index = %d\n", i, b->index); + ConsoleMessage( + "\tdirty flags: 0x%x\n", b->drawn_state.dirty_flags); + ConsoleMessage("\twin: 0x%x\n", b->drawn_state.win); + } } #endif - Index: fvwm/modules/FvwmIconMan/xmanager.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/xmanager.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/xmanager.h --- fvwm/modules/FvwmIconMan/xmanager.h +++ fvwm/modules/FvwmIconMan/xmanager.h @@ -4,49 +4,50 @@ #define FONT_STRING "8x13" #define DEFAULT_BUTTON_WIDTH 200 #define DEFAULT_BUTTON_HEIGHT 17 -#define DEFAULT_NUM_COLS 1 +#define DEFAULT_NUM_COLS 1 #define DEFAULT_NUM_ROWS 0 -extern void draw_managers (void); -extern void draw_manager (WinManager *man); +#include "FvwmIconMan.h" -extern int which_box (WinManager *man, int x, int y); -extern Button *xy_to_button (WinManager *man, int x, int y); +extern void draw_managers(void); +extern void draw_manager(WinManager *man); -extern void delete_windows_button (WinData *win); -extern void resort_windows_button (WinData *win); +extern int which_box(WinManager *man, int x, int y); +extern Button *xy_to_button(WinManager *man, int x, int y); -extern void size_manager (WinManager *man); -extern void init_button_array (ButtonArray *array); -extern void init_boxes (void); -extern void set_shape (WinManager *man); -extern void draw_added_icon (WinManager *man); -extern void draw_deleted_icon (WinManager *man); -extern void move_highlight (WinManager *man, Button *button); +extern void delete_windows_button(WinData *win); +extern void resort_windows_button(WinData *win); + +extern void size_manager(WinManager *man); +extern void init_button_array(ButtonArray *array); +extern void init_boxes(void); +extern void set_shape(WinManager *man); +extern void draw_added_icon(WinManager *man); +extern void draw_deleted_icon(WinManager *man); +extern void move_highlight(WinManager *man, Button *button); #ifdef MINI_ICONS -extern void set_win_picture (WinData *win, Pixmap picture, Pixmap mask, - unsigned int depth, unsigned int width, - unsigned int height); +extern void set_win_picture(WinData *win, Pixmap picture, Pixmap mask, + unsigned int depth, unsigned int width, unsigned int height); #endif -extern void set_win_iconified (WinData *win, int iconified); -extern void set_win_state (WinData *win, int state); -extern void add_win_state (WinData *win, int flag); -extern void del_win_state (WinData *win, int flag); -extern void set_win_displaystring (WinData *win); -extern void set_manager_width (WinManager *man, int width); -extern int change_windows_manager (WinData *win); -extern void check_in_window (WinData *win); -extern void set_manager_window_mapping (WinManager *man, int flag); -extern void man_exposed (WinManager *man, XEvent *theEvent); -extern void force_manager_redraw (WinManager *man); - -extern Button *button_above (WinManager *man, Button *b); -extern Button *button_below (WinManager *man, Button *b); -extern Button *button_right (WinManager *man, Button *b); -extern Button *button_left (WinManager *man, Button *b); -extern Button *button_next (WinManager *man, Button *b); -extern Button *button_prev (WinManager *man, Button *b); - -extern void check_managers_consistency (void); +extern void set_win_iconified(WinData *win, int iconified); +extern void set_win_state(WinData *win, int state); +extern void add_win_state(WinData *win, int flag); +extern void del_win_state(WinData *win, int flag); +extern void set_win_displaystring(WinData *win); +extern void set_manager_width(WinManager *man, int width); +extern int change_windows_manager(WinData *win); +extern void check_in_window(WinData *win); +extern void set_manager_window_mapping(WinManager *man, int flag); +extern void man_exposed(WinManager *man, XEvent *theEvent); +extern void force_manager_redraw(WinManager *man); + +extern Button *button_above(WinManager *man, Button *b); +extern Button *button_below(WinManager *man, Button *b); +extern Button *button_right(WinManager *man, Button *b); +extern Button *button_left(WinManager *man, Button *b); +extern Button *button_next(WinManager *man, Button *b); +extern Button *button_prev(WinManager *man, Button *b); + +extern void check_managers_consistency(void); #endif Index: fvwm/modules/FvwmIdent/FvwmIdent.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIdent/FvwmIdent.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIdent/FvwmIdent.1 --- fvwm/modules/FvwmIdent/FvwmIdent.1 +++ fvwm/modules/FvwmIdent/FvwmIdent.1 @@ -1,69 +1,56 @@ .\" $OpenBSD: FvwmIdent.1,v 1.1.1.1 2006/11/26 10:53:51 matthieu Exp $ .\" t -.\" @(#)FvwmIdent.1 1/12/94 -.TH FvwmIdent 1 "Jan 28 1994" 1.20 +.\" @(#)FvwmIdent.1 1/12/94 +.TH FVWMIDENT 1 "January 28, 1994" "1.20" "FVWM Modules" .UC .SH NAME FvwmIdent \- the FVWM identify-window module .SH SYNOPSIS FvwmIdent is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -The FvwmIdent module questions the user to select a target window, if -the module was not launched from within a window context in Fvwm. -After that, it pops up a window with information about the window -which was selected. - -FvwmIdent reads the same .fvwmrc file as fvwm reads when it starts up, -and looks for lines similar to "*FvwmIdentFore green". - +The FvwmIdent module questions the user to select a target window if the +module was not launched from within a window context in Fvwm. +.PP +After that, it pops up a window with information about the window which +was selected. +.PP +FvwmIdent reads the same .fvwmrc file as fvwm reads when it starts up and +looks for lines similar to "*FvwmIdentFore green". .SH COPYRIGHTS -The FvwmIdent program, and the concept for -interfacing this module to the Window Manager, are all original work -by Robert Nation Nobutaka Suzuki. - +The FvwmIdent program, and the concept for interfacing this module to the +Window Manager, are original work by Robert Nation and Nobutaka Suzuki. +.PP Copyright 1994, Robert Nation and Nobutaka Suzuki. No guarantees or -warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - - +warranties or anything are provided or implied in any way whatsoever. +.PP +Use this program at your own risk. Permission to use this program for any +purpose is given, as long as the copyright is kept intact. .SH INITIALIZATION -During initialization, \fIFvwmIdent\fP will eventually search a -configuration file which describes the colors and font to use. -The configuration file is the same file that fvwm used during initialization. - +During initialization, \fIFvwmIdent\fP will search a configuration file +which describes the colors and font to use. The configuration file is the +same file that fvwm used during initialization. +.PP If the FvwmIdent executable is linked to another name, ie ln -s FvwmIdent MoreIdentify, then another module called MoreIdentify can be started, with a completely different configuration than FvwmIdent, -simply by changing the keyword FvwmIdent to MoreIdentify. This way multiple -clutter-reduction programs can be used. - +simply by changing the keyword FvwmIdent to MoreIdentify. This way +multiple clutter-reduction programs can be used. .SH INVOCATION -FvwmIdent can be invoked by binding the action 'Module -FvwmIdent' to a menu or key-stroke in the .fvwmrc file. -Fvwm will search -directory specified in the ModulePath configuration option to attempt -to locate FvwmIdent. Although nothing keeps you from launching -FvwmIdent at start-up time, you probably don't want to. - +FvwmIdent can be invoked by binding the action "Module FvwmIdent" to a +menu or key-stroke in the .fvwmrc file. +.PP +Fvwm will search the directory specified in the ModulePath configuration +option to locate FvwmIdent. Although nothing keeps you from launching +FvwmIdent at start-up time, you probably do not want to. .SH CONFIGURATION OPTIONS -FvwmIdent reads the same .fvwmrc file as fvwm reads when it starts up, -and looks for lines as listed below: - +FvwmIdent reads the same .fvwmrc file as fvwm reads when it starts up and +looks for lines as listed below: .IP "*FvwmIdentFore \fIcolor\fP" Tells the module to use \fIcolor\fP instead of black for text. - .IP "*FvwmIdentBack \fIcolor\fP" Tells the module to use \fIcolor\fP instead of white for the window background. - .IP "*FvwmIdentFont \fIfontname\fP" Tells the module to use \fIfontname\fP instead of fixed for text. - - .SH AUTHOR -Robert Nation and and Nobutaka -Suzuki (nobuta-s@is.aist-nara.ac.jp). - +Robert Nation and Nobutaka Suzuki (nobuta-s@is.aist-nara.ac.jp). Index: fvwm/modules/FvwmIdent/FvwmIdent.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIdent/FvwmIdent.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIdent/FvwmIdent.c --- fvwm/modules/FvwmIdent/FvwmIdent.c +++ fvwm/modules/FvwmIdent/FvwmIdent.c @@ -12,30 +12,32 @@ #define FALSE #define YES "Yes" -#define NO "No" +#define NO "No" -#include "config.h" +#include +#include -#include -#include #include +#include +#include #include -#include -#include + +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" #if HAVE_SYS_SELECT_H #include #endif -#include -#include -#include +#include +#include #include -#include #include -#include -#include +#include #include +#include +#include +#include #include "../../fvwm/module.h" #include "FvwmIdent.h" @@ -44,7 +46,7 @@ char *MyName; int fd_width; int fd[2]; -Display *dpy; /* which display are we talking to */ +Display *dpy; /* which display are we talking to */ Window Root; int screen; int x_fd; @@ -56,23 +58,23 @@ char *ForeColor = "black"; char *font_string = "fixed"; Pixel back_pix, fore_pix; -GC NormalGC; +GC NormalGC; Window main_win; Window app_win; XFontStruct *font; -int Width, Height,win_x,win_y; +int Width, Height, win_x, win_y; -#define MW_EVENTS (ExposureMask | ButtonReleaseMask | KeyReleaseMask) +#define MW_EVENTS (ExposureMask | ButtonReleaseMask | KeyReleaseMask) static Atom wm_del_win; struct target_struct target; -int found=0; +int found = 0; -static int ListSize=0; +static int ListSize = 0; -struct Item* itemlistRoot = NULL; +struct Item *itemlistRoot = NULL; int max_col1, max_col2; char id[15], desktop[10], swidth[10], sheight[10], borderw[10], geometry[30]; char mymin_aspect[11], max_aspect[11]; @@ -83,97 +85,94 @@ char mymin_aspect[11], max_aspect[11]; * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - char *display_name = NULL; - int Clength; - char *tline; - - /* Save the program name for error messages and config parsing */ - temp = argv[0]; - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - Clength = strlen(MyName); - - if((argc != 6)&&(argc != 7)) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - /* Dead pipe == dead fvwm */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - /* An application window may have already been selected - look for it */ - sscanf(argv[4],"%x",(unsigned int *)&app_win); - - /* Open the Display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - x_fd = XConnectionNumber(dpy); - screen= DefaultScreen(dpy); - Root = RootWindow(dpy, screen); - d_depth = DefaultDepth(dpy, screen); - - ScreenHeight = DisplayHeight(dpy,screen); - ScreenWidth = DisplayWidth(dpy,screen); - - SetMessageMask(fd,M_CONFIGURE_WINDOW|M_WINDOW_NAME|M_ICON_NAME| - M_RES_CLASS| M_RES_NAME| M_END_WINDOWLIST|M_CONFIG_INFO| - M_END_CONFIG_INFO); - /* scan config file for set-up parameters */ - /* Colors and fonts */ - - GetConfigLine(fd,&tline); - - while(tline != (char *)0) - { - if(strlen(tline)>1) - { - if(strncasecmp(tline, CatString3(MyName,"Font",""),Clength+4)==0) - { - CopyString(&font_string,&tline[Clength+4]); - } - else if(strncasecmp(tline,CatString3(MyName,"Fore",""), - Clength+4)==0) - { - CopyString(&ForeColor,&tline[Clength+4]); - } - else if(strncasecmp(tline,CatString3(MyName, "Back",""), - Clength+4)==0) - { - CopyString(&BackColor,&tline[Clength+4]); - } + char *temp, *s; + char *display_name = NULL; + int Clength; + char *tline; + + /* Save the program name for error messages and config parsing */ + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + size_t name_len = strlen(temp); + MyName = xmalloc(name_len + 2); + strlcpy(MyName, "*", name_len + 2); + strlcat(MyName, temp, name_len + 2); + Clength = strlen(MyName); + + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); + } + + /* Dead pipe == dead fvwm */ + signal(SIGPIPE, DeadPipe); + + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + /* An application window may have already been selected - look for it */ + sscanf(argv[4], "%x", (unsigned int *)&app_win); + + /* Open the Display */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + x_fd = XConnectionNumber(dpy); + screen = DefaultScreen(dpy); + Root = RootWindow(dpy, screen); + d_depth = DefaultDepth(dpy, screen); + + ScreenHeight = DisplayHeight(dpy, screen); + ScreenWidth = DisplayWidth(dpy, screen); + + SetMessageMask(fd, M_CONFIGURE_WINDOW | M_WINDOW_NAME | M_ICON_NAME | + M_RES_CLASS | M_RES_NAME | M_END_WINDOWLIST | + M_CONFIG_INFO | M_END_CONFIG_INFO); + /* scan config file for set-up parameters */ + /* Colors and fonts */ + + GetConfigLine(fd, &tline); + + while (tline != (char *)0) { + if (strlen(tline) > 1) { + if (strncasecmp(tline, CatString3(MyName, "Font", ""), + Clength + 4) == 0) { + CopyString(&font_string, &tline[Clength + 4]); + } else if (strncasecmp(tline, + CatString3(MyName, "Fore", ""), + Clength + 4) == 0) { + CopyString(&ForeColor, &tline[Clength + 4]); + } else if (strncasecmp(tline, + CatString3(MyName, "Back", ""), + Clength + 4) == 0) { + CopyString(&BackColor, &tline[Clength + 4]); + } + } + GetConfigLine(fd, &tline); } - GetConfigLine(fd,&tline); - } - if(app_win == 0) - GetTargetWindow(&app_win); + if (app_win == 0) + GetTargetWindow(&app_win); - fd_width = GetFdWidth(); + fd_width = GetFdWidth(); - /* Create a list of all windows */ - /* Request a list of all windows, - * wait for ConfigureWindow packets */ - SendInfo(fd,"Send_WindowList",0); + /* Create a list of all windows */ + /* Request a list of all windows, + * wait for ConfigureWindow packets */ + SendInfo(fd, "Send_WindowList", 0); - Loop(fd); - return 0; + Loop(fd); + return 0; } /************************************************************************** @@ -181,66 +180,64 @@ int main(int argc, char **argv) * Read the entire window list from fvwm * *************************************************************************/ -void Loop(int *fd) +void +Loop(int *fd) { - unsigned long header[4], *body; + unsigned long header[4], *body; - while(1) - { - if(ReadFvwmPacket(fd[1],header,&body) > 0) - { - process_message(header[1],body); - free(body); + sandbox_x11_only("FvwmIdent"); + sandbox_x11_only("FvwmIdent"); + + while (1) { + if (ReadFvwmPacket(fd[1], header, &body) > 0) { + process_message(header[1], body); + free(body); + } } - } } - /************************************************************************** * * Process window list messages * *************************************************************************/ -void process_message(unsigned long type,unsigned long *body) +void +process_message(unsigned long type, unsigned long *body) { - switch(type) - { - case M_CONFIGURE_WINDOW: - list_configure(body); - break; - case M_WINDOW_NAME: - list_window_name(body); - break; - case M_ICON_NAME: - list_icon_name(body); - break; - case M_RES_CLASS: - list_class(body); - break; - case M_RES_NAME: - list_res_name(body); - break; - case M_END_WINDOWLIST: - list_end(); - break; - default: - break; - - } + switch (type) { + case M_CONFIGURE_WINDOW: + list_configure(body); + break; + case M_WINDOW_NAME: + list_window_name(body); + break; + case M_ICON_NAME: + list_icon_name(body); + break; + case M_RES_CLASS: + list_class(body); + break; + case M_RES_NAME: + list_res_name(body); + break; + case M_END_WINDOWLIST: + list_end(); + break; + default: + break; + } } - - - /*********************************************************************** * * Detected a broken pipe - time to exit * **********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - freelist(); - exit(0); + freelist(); + exit(0); } /*********************************************************************** @@ -248,31 +245,30 @@ void DeadPipe(int nonsense) * Got window configuration info - if its our window, safe data * ***********************************************************************/ -void list_configure(unsigned long *body) +void +list_configure(unsigned long *body) { - if((app_win == (Window)body[1])||(app_win == (Window)body[0]) - ||((body[19] != 0)&&(app_win == (Window)body[19])) - ||((body[19] != 0)&&(app_win == (Window)body[20]))) - { - app_win = body[1]; - target.id = body[0]; - target.frame = body[1]; - target.frame_x = body[3]; - target.frame_y = body[4]; - target.frame_w = body[5]; - target.frame_h = body[6]; - target.desktop = body[7]; - target.flags = body[8]; - target.title_h = body[9]; - target.border_w = body[10]; - target.base_w = body[11]; - target.base_h = body[12]; - target.width_inc = body[13]; - target.height_inc = body[14]; - target.gravity = body[21]; - found = 1; - } - + if ((app_win == (Window)body[1]) || (app_win == (Window)body[0]) || + ((body[19] != 0) && (app_win == (Window)body[19])) || + ((body[19] != 0) && (app_win == (Window)body[20]))) { + app_win = body[1]; + target.id = body[0]; + target.frame = body[1]; + target.frame_x = body[3]; + target.frame_y = body[4]; + target.frame_w = body[5]; + target.frame_h = body[6]; + target.desktop = body[7]; + target.flags = body[8]; + target.title_h = body[9]; + target.border_w = body[10]; + target.base_w = body[11]; + target.base_h = body[12]; + target.width_inc = body[13]; + target.height_inc = body[14]; + target.gravity = body[21]; + found = 1; + } } /************************************************************************* @@ -280,12 +276,12 @@ void list_configure(unsigned long *body) * Capture Window name info * ************************************************************************/ -void list_window_name(unsigned long *body) +void +list_window_name(unsigned long *body) { - if((app_win == (Window)body[1])||(app_win == (Window)body[0])) - { - strncpy(target.name,(char *)&body[3],255); - } + if ((app_win == (Window)body[1]) || (app_win == (Window)body[0])) { + strncpy(target.name, (char *)&body[3], 255); + } } /************************************************************************* @@ -293,178 +289,162 @@ void list_window_name(unsigned long *body) * Capture Window Icon name info * ************************************************************************/ -void list_icon_name(unsigned long *body) +void +list_icon_name(unsigned long *body) { - if((app_win == (Window)body[1])||(app_win == (Window)body[0])) - { - strncat(target.icon_name,(char *)&body[3],255); - } + if ((app_win == (Window)body[1]) || (app_win == (Window)body[0])) { + strncat(target.icon_name, (char *)&body[3], 255); + } } - /************************************************************************* * * Capture Window class name info * ************************************************************************/ -void list_class(unsigned long *body) +void +list_class(unsigned long *body) { - if((app_win == (Window)body[1])||(app_win == (Window)body[0])) - { - strncat(target.class,(char *)&body[3],255); - } + if ((app_win == (Window)body[1]) || (app_win == (Window)body[0])) { + strncat(target.class, (char *)&body[3], 255); + } } - /************************************************************************* * * Capture Window resource info * ************************************************************************/ -void list_res_name(unsigned long *body) +void +list_res_name(unsigned long *body) { - if((app_win == (Window)body[1])||(app_win == (Window)body[0])) - { - strncat(target.res,(char *)&body[3],255); - } + if ((app_win == (Window)body[1]) || (app_win == (Window)body[0])) { + strncat(target.res, (char *)&body[3], 255); + } } - /************************************************************************* * * End of window list, open an x window and display data in it * ************************************************************************/ XSizeHints mysizehints; -void list_end(void) +void +list_end(void) { - XGCValues gcv; - unsigned long gcm; - int lmax,height; - XEvent Event; - Window JunkRoot, JunkChild; - int JunkX, JunkY; - unsigned int JunkMask; - int x,y; - - if(!found) - { -/* fprintf(stderr,"%s: Couldn't find app window\n",MyName); */ - exit(0); - } - - close(fd[0]); - close(fd[1]); - - /* load the font */ - if ((font = XLoadQueryFont(dpy, font_string)) == NULL) - { - if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) - exit(1); - }; - - /* make window infomation list */ - MakeList(); - - /* size and create the window */ - lmax = max_col1 + max_col2 + 15; - - height = ListSize*(font->ascent+font->descent); - - mysizehints.flags= - USSize|USPosition|PWinGravity|PResizeInc|PBaseSize|PMinSize|PMaxSize; - /* subtract one for the right/bottom border */ - mysizehints.width = lmax+10; - mysizehints.height=height+10; - mysizehints.width_inc = 1; - mysizehints.height_inc = 1; - mysizehints.base_height = mysizehints.height; - mysizehints.base_width = mysizehints.width; - mysizehints.min_height = mysizehints.height; - mysizehints.min_width = mysizehints.width; - mysizehints.max_height = mysizehints.height; - mysizehints.max_width = mysizehints.width; - XQueryPointer( dpy, Root, &JunkRoot, &JunkChild, - &x, &y, &JunkX, &JunkY, &JunkMask); - mysizehints.win_gravity = NorthWestGravity; - - if((y+height+100)>ScreenHeight) - { - y = ScreenHeight - height - 10; - mysizehints.win_gravity = SouthWestGravity; - } - - if((x+lmax+100)>ScreenWidth) - { - x = ScreenWidth - lmax - 10; - if((y+height+100)>ScreenHeight) - mysizehints.win_gravity = SouthEastGravity; - else - mysizehints.win_gravity = NorthEastGravity; - } - mysizehints.x = x; - mysizehints.y = y; - - - - if(d_depth < 2) - { - back_pix = GetColor("white"); - fore_pix = GetColor("black"); - } - else - { - back_pix = GetColor(BackColor); - fore_pix = GetColor(ForeColor); - - } - - main_win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y, - mysizehints.width,mysizehints.height, - 0,fore_pix,back_pix); - XSetTransientForHint(dpy,main_win,app_win); - wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); - XSetWMProtocols(dpy,main_win,&wm_del_win,1); - - XSetWMNormalHints(dpy,main_win,&mysizehints); - XSelectInput(dpy,main_win,MW_EVENTS); - change_window_name(&MyName[1]); - - gcm = GCForeground|GCBackground|GCFont; - gcv.foreground = fore_pix; - gcv.background = back_pix; - gcv.font = font->fid; - NormalGC = XCreateGC(dpy, Root, gcm, &gcv); - XMapWindow(dpy,main_win); - - /* Window is created. Display it until the user clicks or deletes it. */ - while(1) - { - XNextEvent(dpy,&Event); - switch(Event.type) - { - case Expose: - if(Event.xexpose.count == 0) - RedrawWindow(); - break; - case KeyRelease: - case ButtonRelease: - freelist(); - exit(0); - case ClientMessage: - if (Event.xclient.format==32 && Event.xclient.data.l[0]==wm_del_win) - { - freelist(); - exit(0); - } - default: - break; + XGCValues gcv; + unsigned long gcm; + int lmax, height; + XEvent Event; + Window JunkRoot, JunkChild; + int JunkX, JunkY; + unsigned int JunkMask; + int x, y; + + if (!found) { + /* fprintf(stderr,"%s: Couldn't find app window\n",MyName); + */ + exit(0); } - } -} + close(fd[0]); + close(fd[1]); + + /* load the font */ + if ((font = XLoadQueryFont(dpy, font_string)) == NULL) { + if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) + exit(1); + } + + /* make window infomation list */ + MakeList(); + + /* size and create the window */ + lmax = max_col1 + max_col2 + 15; + + height = ListSize * (font->ascent + font->descent); + + mysizehints.flags = USSize | USPosition | PWinGravity | PResizeInc | + PBaseSize | PMinSize | PMaxSize; + /* subtract one for the right/bottom border */ + mysizehints.width = lmax + 10; + mysizehints.height = height + 10; + mysizehints.width_inc = 1; + mysizehints.height_inc = 1; + mysizehints.base_height = mysizehints.height; + mysizehints.base_width = mysizehints.width; + mysizehints.min_height = mysizehints.height; + mysizehints.min_width = mysizehints.width; + mysizehints.max_height = mysizehints.height; + mysizehints.max_width = mysizehints.width; + XQueryPointer(dpy, Root, &JunkRoot, &JunkChild, &x, &y, &JunkX, &JunkY, + &JunkMask); + mysizehints.win_gravity = NorthWestGravity; + + if ((y + height + 100) > ScreenHeight) { + y = ScreenHeight - height - 10; + mysizehints.win_gravity = SouthWestGravity; + } + if ((x + lmax + 100) > ScreenWidth) { + x = ScreenWidth - lmax - 10; + if ((y + height + 100) > ScreenHeight) + mysizehints.win_gravity = SouthEastGravity; + else + mysizehints.win_gravity = NorthEastGravity; + } + mysizehints.x = x; + mysizehints.y = y; + + if (d_depth < 2) { + back_pix = GetColor("white"); + fore_pix = GetColor("black"); + } else { + back_pix = GetColor(BackColor); + fore_pix = GetColor(ForeColor); + } + main_win = XCreateSimpleWindow(dpy, Root, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, 0, fore_pix, back_pix); + XSetTransientForHint(dpy, main_win, app_win); + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + XSetWMProtocols(dpy, main_win, &wm_del_win, 1); + + XSetWMNormalHints(dpy, main_win, &mysizehints); + XSelectInput(dpy, main_win, MW_EVENTS); + change_window_name(&MyName[1]); + + gcm = GCForeground | GCBackground | GCFont; + gcv.foreground = fore_pix; + gcv.background = back_pix; + gcv.font = font->fid; + NormalGC = XCreateGC(dpy, Root, gcm, &gcv); + XMapWindow(dpy, main_win); + + /* Window is created. Display it until the user clicks or deletes it. */ + sandbox_x11_only("FvwmIdent"); + while (1) { + XNextEvent(dpy, &Event); + switch (Event.type) { + case Expose: + if (Event.xexpose.count == 0) + RedrawWindow(); + break; + case KeyRelease: + case ButtonRelease: + freelist(); + exit(0); + case ClientMessage: + if (Event.xclient.format == 32 && + Event.xclient.data.l[0] == wm_del_win) { + freelist(); + exit(0); + } + default: + break; + } + } +} /********************************************************************** * @@ -472,36 +452,32 @@ void list_end(void) * the user to select one * *********************************************************************/ -void GetTargetWindow(Window *app_win) +void +GetTargetWindow(Window *app_win) { - XEvent eventp; - int val = -10,trials; - - trials = 0; - while((trials <100)&&(val != GrabSuccess)) - { - val=XGrabPointer(dpy, Root, True, - ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, Root, - XCreateFontCursor(dpy,XC_crosshair), - CurrentTime); - if(val != GrabSuccess) - { - usleep(1000); + XEvent eventp; + int val = -10, trials; + + trials = 0; + while ((trials < 100) && (val != GrabSuccess)) { + val = XGrabPointer(dpy, Root, True, ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, Root, + XCreateFontCursor(dpy, XC_crosshair), CurrentTime); + if (val != GrabSuccess) { + usleep(1000); + } + trials++; } - trials++; - } - if(val != GrabSuccess) - { - fprintf(stderr,"%s: Couldn't grab the cursor!\n",MyName); - exit(1); - } - XMaskEvent(dpy, ButtonReleaseMask,&eventp); - XUngrabPointer(dpy,CurrentTime); - XSync(dpy,0); - *app_win = eventp.xany.window; - if(eventp.xbutton.subwindow != None) - *app_win = eventp.xbutton.subwindow; + if (val != GrabSuccess) { + fprintf(stderr, "%s: Couldn't grab the cursor!\n", MyName); + exit(1); + } + XMaskEvent(dpy, ButtonReleaseMask, &eventp); + XUngrabPointer(dpy, CurrentTime); + XSync(dpy, 0); + *app_win = eventp.xany.window; + if (eventp.xbutton.subwindow != None) + *app_win = eventp.xbutton.subwindow; } /************************************************************************ @@ -509,297 +485,277 @@ void GetTargetWindow(Window *app_win) * Draw the window * ***********************************************************************/ -void RedrawWindow(void) +void +RedrawWindow(void) { - int fontheight,i=0; - struct Item *cur = itemlistRoot; - - fontheight = font->ascent + font->descent; - - while(cur != NULL) - { - /* first column */ - XDrawString(dpy,main_win,NormalGC,5,5+font->ascent+i*fontheight, - cur->col1,strlen(cur->col1)); - /* second column */ - XDrawString(dpy,main_win,NormalGC,10+max_col1,5+font->ascent+i*fontheight, - cur->col2,strlen(cur->col2)); - ++i; - cur = cur->next; - } + int fontheight, i = 0; + struct Item *cur = itemlistRoot; + + fontheight = font->ascent + font->descent; + + while (cur != NULL) { + /* first column */ + XDrawString(dpy, main_win, NormalGC, 5, + 5 + font->ascent + i * fontheight, cur->col1, + strlen(cur->col1)); + /* second column */ + XDrawString(dpy, main_win, NormalGC, 10 + max_col1, + 5 + font->ascent + i * fontheight, cur->col2, + strlen(cur->col2)); + ++i; + cur = cur->next; + } } /************************************************************************** * Change the window name displayed in the title bar. **************************************************************************/ -void change_window_name(char *str) +void +change_window_name(char *str) { - XTextProperty name; - - if (XStringListToTextProperty(&str,1,&name) == 0) - { - fprintf(stderr,"%s: cannot allocate window name",MyName); - return; - } - XSetWMName(dpy,main_win,&name); - XSetWMIconName(dpy,main_win,&name); - XFree(name.value); -} + XTextProperty name; + if (XStringListToTextProperty(&str, 1, &name) == 0) { + fprintf(stderr, "%s: cannot allocate window name", MyName); + return; + } + XSetWMName(dpy, main_win, &name); + XSetWMIconName(dpy, main_win, &name); + XFree(name.value); +} /************************************************************************** -* -* Add s1(string at first column) and s2(string at second column) to itemlist -* + * + * Add s1(string at first column) and s2(string at second column) to itemlist + * *************************************************************************/ -void AddToList(char *s1, char* s2) +void +AddToList(char *s1, char *s2) { - int tw1, tw2; - struct Item* item, *cur = itemlistRoot; - - tw1 = XTextWidth(font, s1, strlen(s1)); - tw2 = XTextWidth(font, s2, strlen(s2)); - max_col1 = max_col1 > tw1 ? max_col1 : tw1; - max_col2 = max_col2 > tw2 ? max_col2 : tw2; - - item = (struct Item*)safemalloc(sizeof(struct Item)); - - item->col1 = s1; - item->col2 = s2; - item->next = NULL; - - if (cur == NULL) - itemlistRoot = item; - else { - while(cur->next != NULL) - cur = cur->next; - cur->next = item; - } - ListSize++; + int tw1, tw2; + struct Item *item, *cur = itemlistRoot; + + tw1 = XTextWidth(font, s1, strlen(s1)); + tw2 = XTextWidth(font, s2, strlen(s2)); + max_col1 = max_col1 > tw1 ? max_col1 : tw1; + max_col2 = max_col2 > tw2 ? max_col2 : tw2; + + item = (struct Item *)xmalloc(sizeof(struct Item)); + + item->col1 = s1; + item->col2 = s2; + item->next = NULL; + + if (cur == NULL) + itemlistRoot = item; + else { + while (cur->next != NULL) + cur = cur->next; + cur->next = item; + } + ListSize++; } -void MakeList(void) +void +MakeList(void) { - int bw,width,height,x1,y1,x2,y2; - char loc[20]; - static char xstr[6],ystr[6]; - - ListSize = 0; - - bw = 2*target.border_w; - width = target.frame_w - bw; - height = target.frame_h - target.title_h - bw; - - sprintf(desktop, "%ld", target.desktop); - sprintf(id, "0x%x", (unsigned int)target.id); - sprintf(swidth, "%d", width); - sprintf(sheight, "%d", height); - sprintf(borderw, "%ld", target.border_w); - sprintf(xstr, "%ld", target.frame_x); - sprintf(ystr, "%ld", target.frame_y); - - AddToList("Name:", target.name); - AddToList("Icon Name:", target.icon_name); - AddToList("Class:", target.class); - AddToList("Resource:", target.res); - AddToList("Window ID:", id); - AddToList("Desk:", desktop); - AddToList("Width:", swidth); - AddToList("Height:", sheight); - AddToList("X (current page):", xstr); - AddToList("Y (current page):", ystr); - AddToList("Boundary Width:", borderw); - AddToList("Sticky:", (target.flags & STICKY ? YES : NO)); - AddToList("Ontop:", (target.flags & ONTOP ? YES : NO)); - AddToList("NoTitle:", (target.flags & TITLE ? NO : YES)); - AddToList("Iconified:", (target.flags & ICONIFIED ? YES : NO)); - AddToList("Transient:", (target.flags & TRANSIENT ? YES : NO)); - - switch(target.gravity) - { - case ForgetGravity: - AddToList("Gravity:", "Forget"); - break; - case NorthWestGravity: - AddToList("Gravity:", "NorthWest"); - break; - case NorthGravity: - AddToList("Gravity:", "North"); - break; - case NorthEastGravity: - AddToList("Gravity:", "NorthEast"); - break; - case WestGravity: - AddToList("Gravity:", "West"); - break; - case CenterGravity: - AddToList("Gravity:", "Center"); - break; - case EastGravity: - AddToList("Gravity:", "East"); - break; - case SouthWestGravity: - AddToList("Gravity:", "SouthWest"); - break; - case SouthGravity: - AddToList("Gravity:", "South"); - break; - case SouthEastGravity: - AddToList("Gravity:", "SouthEast"); - break; - case StaticGravity: - AddToList("Gravity:", "Static"); - break; - default: - AddToList("Gravity:", "Unknown"); - break; - } - x1 = target.frame_x; - if(x1 < 0) - x1 = 0; - x2 = ScreenWidth - x1 - target.frame_w; - if(x2 < 0) - x2 = 0; - y1 = target.frame_y; - if(y1 < 0) - y1 = 0; - y2 = ScreenHeight - y1 - target.frame_h; - if(y2 < 0) - y2 = 0; - width = (width - target.base_w)/target.width_inc; - height = (height - target.base_h)/target.height_inc; - - sprintf(loc,"%dx%d",width,height); - strcpy(geometry, loc); - - if ((target.gravity == EastGravity) ||(target.gravity == NorthEastGravity)|| - (target.gravity == SouthEastGravity)) - sprintf(loc,"-%d",x2); - else - sprintf(loc,"+%d",x1); - strcat(geometry, loc); - - if((target.gravity == SouthGravity)||(target.gravity == SouthEastGravity)|| - (target.gravity == SouthWestGravity)) - sprintf(loc,"-%d",y2); - else - sprintf(loc,"+%d",y1); - strcat(geometry, loc); - AddToList("Geometry:", geometry); - -#if 0 - { - char tmp[20], *foo; - sprintf(tmp,"%d", target.base_w); - foo = strdup(tmp); - AddToList(" - base_w:", foo); - sprintf(tmp,"%d", target.width_inc); - foo = strdup(tmp); - AddToList(" - width_inc:", foo); - sprintf(tmp,"%d", target.base_h); - foo = strdup(tmp); - AddToList(" - base_h:", foo); - sprintf(tmp,"%d", target.height_inc); - foo = strdup(tmp); - AddToList(" - height_inc:", foo); - } -#endif + int bw, width, height, x1, y1, x2, y2; + char loc[20]; + static char xstr[6], ystr[6]; + + ListSize = 0; + + bw = 2 * target.border_w; + width = target.frame_w - bw; + height = target.frame_h - target.title_h - bw; + + snprintf(desktop, sizeof(desktop), "%ld", target.desktop); + snprintf(id, sizeof(id), "0x%x", (unsigned int)target.id); + snprintf(swidth, sizeof(swidth), "%d", width); + snprintf(sheight, sizeof(sheight), "%d", height); + snprintf(borderw, sizeof(borderw), "%ld", target.border_w); + snprintf(xstr, sizeof(xstr), "%ld", target.frame_x); + snprintf(ystr, sizeof(ystr), "%ld", target.frame_y); + + AddToList("Name:", target.name); + AddToList("Icon Name:", target.icon_name); + AddToList("Class:", target.class); + AddToList("Resource:", target.res); + AddToList("Window ID:", id); + AddToList("Desk:", desktop); + AddToList("Width:", swidth); + AddToList("Height:", sheight); + AddToList("X (current page):", xstr); + AddToList("Y (current page):", ystr); + AddToList("Boundary Width:", borderw); + AddToList("Sticky:", (target.flags & STICKY ? YES : NO)); + AddToList("Ontop:", (target.flags & ONTOP ? YES : NO)); + AddToList("NoTitle:", (target.flags & TITLE ? NO : YES)); + AddToList("Iconified:", (target.flags & ICONIFIED ? YES : NO)); + AddToList("Transient:", (target.flags & TRANSIENT ? YES : NO)); + + switch (target.gravity) { + case ForgetGravity: + AddToList("Gravity:", "Forget"); + break; + case NorthWestGravity: + AddToList("Gravity:", "NorthWest"); + break; + case NorthGravity: + AddToList("Gravity:", "North"); + break; + case NorthEastGravity: + AddToList("Gravity:", "NorthEast"); + break; + case WestGravity: + AddToList("Gravity:", "West"); + break; + case CenterGravity: + AddToList("Gravity:", "Center"); + break; + case EastGravity: + AddToList("Gravity:", "East"); + break; + case SouthWestGravity: + AddToList("Gravity:", "SouthWest"); + break; + case SouthGravity: + AddToList("Gravity:", "South"); + break; + case SouthEastGravity: + AddToList("Gravity:", "SouthEast"); + break; + case StaticGravity: + AddToList("Gravity:", "Static"); + break; + default: + AddToList("Gravity:", "Unknown"); + break; + } + x1 = target.frame_x; + if (x1 < 0) + x1 = 0; + x2 = ScreenWidth - x1 - target.frame_w; + if (x2 < 0) + x2 = 0; + y1 = target.frame_y; + if (y1 < 0) + y1 = 0; + y2 = ScreenHeight - y1 - target.frame_h; + if (y2 < 0) + y2 = 0; + width = (width - target.base_w) / target.width_inc; + height = (height - target.base_h) / target.height_inc; + + snprintf(loc, sizeof(loc), "%dx%d", width, height); + strlcpy(geometry, loc, sizeof(geometry)); + + if ((target.gravity == EastGravity) || + (target.gravity == NorthEastGravity) || + (target.gravity == SouthEastGravity)) + snprintf(loc, sizeof(loc), "-%d", x2); + else + snprintf(loc, sizeof(loc), "+%d", x1); + strlcat(geometry, loc, sizeof(geometry)); + + if ((target.gravity == SouthGravity) || + (target.gravity == SouthEastGravity) || + (target.gravity == SouthWestGravity)) + snprintf(loc, sizeof(loc), "-%d", y2); + else + snprintf(loc, sizeof(loc), "+%d", y1); + strlcat(geometry, loc, sizeof(geometry)); + AddToList("Geometry:", geometry); - { - Atom *protocols = NULL, *ap; - Atom _XA_WM_TAKE_FOCUS = XInternAtom(dpy, "WM_TAKE_FOCUS", False); - XWMHints *wmhintsp = XGetWMHints(dpy,target.id); - int i,n; - Boolean HasTakeFocus=False,InputField=True; - char *focus_policy="",*ifstr="",*tfstr=""; - - if (wmhintsp) - { - InputField=wmhintsp->input; - ifstr=InputField?"True":"False"; - XFree(wmhintsp); - } - else - { - ifstr="XWMHints missing"; - } - if (XGetWMProtocols(dpy,target.id,&protocols,&n)) - { - for (i = 0, ap = protocols; i < n; i++, ap++) - { - if (*ap == (Atom)_XA_WM_TAKE_FOCUS) - HasTakeFocus = True; - } - tfstr=HasTakeFocus?"Present":"Absent"; - XFree(protocols); - } - else - { - tfstr="XGetWMProtocols failed"; - } - if (HasTakeFocus) - { - if (InputField) - { - focus_policy = "Locally Active"; - } - else - { - focus_policy = "Globally Active"; - } - } - else - { - if (InputField) - { - focus_policy = "Passive"; - } - else - { - focus_policy = "No Input"; - } - } - AddToList("Focus Policy:",focus_policy); - AddToList(" - Input Field:",ifstr); - AddToList(" - WM_TAKE_FOCUS:",tfstr); - { - long supplied_return; /* flags, hints that were supplied */ - int getrc; - XSizeHints *size_hints = XAllocSizeHints(); /* the size hints */ - if ((getrc = XGetWMSizeHints(dpy,target.id, /* get size hints */ - size_hints, /* Hints */ - &supplied_return, - XA_WM_ZOOM_HINTS))) { - if (supplied_return & PAspect) { /* if window has a aspect ratio */ - sprintf(mymin_aspect, "%d/%d", size_hints->min_aspect.x, - size_hints->min_aspect.y); - AddToList("Minimum aspect ratio:",mymin_aspect); - sprintf(max_aspect, "%d/%d", size_hints->max_aspect.x, - size_hints->max_aspect.y); - AddToList("Maximum aspect ratio:",max_aspect); - } /* end aspect ratio */ - XFree(size_hints); - } /* end getsizehints worked */ - } - } + { + Atom *protocols = NULL, *ap; + Atom _XA_WM_TAKE_FOCUS = + XInternAtom(dpy, "WM_TAKE_FOCUS", False); + XWMHints *wmhintsp = XGetWMHints(dpy, target.id); + int i, n; + Boolean HasTakeFocus = False, InputField = True; + char *focus_policy = "", *ifstr = "", *tfstr = ""; + + if (wmhintsp) { + InputField = wmhintsp->input; + ifstr = InputField ? "True" : "False"; + XFree(wmhintsp); + } else { + ifstr = "XWMHints missing"; + } + if (XGetWMProtocols(dpy, target.id, &protocols, &n)) { + for (i = 0, ap = protocols; i < n; i++, ap++) { + if (*ap == (Atom)_XA_WM_TAKE_FOCUS) + HasTakeFocus = True; + } + tfstr = HasTakeFocus ? "Present" : "Absent"; + XFree(protocols); + } else { + tfstr = "XGetWMProtocols failed"; + } + if (HasTakeFocus) { + if (InputField) { + focus_policy = "Locally Active"; + } else { + focus_policy = "Globally Active"; + } + } else { + if (InputField) { + focus_policy = "Passive"; + } else { + focus_policy = "No Input"; + } + } + AddToList("Focus Policy:", focus_policy); + AddToList(" - Input Field:", ifstr); + AddToList(" - WM_TAKE_FOCUS:", tfstr); + { + long supplied_return; /* flags, hints that were supplied + */ + int getrc; + XSizeHints *size_hints = + XAllocSizeHints(); /* the size hints */ + if ((getrc = XGetWMSizeHints(dpy, + target.id, /* get size hints */ + size_hints, /* Hints */ + &supplied_return, XA_WM_ZOOM_HINTS))) { + if (supplied_return & + PAspect) { /* if window has a aspect ratio + */ + snprintf(mymin_aspect, + sizeof(mymin_aspect), "%d/%d", + size_hints->min_aspect.x, + size_hints->min_aspect.y); + AddToList("Minimum aspect ratio:", + mymin_aspect); + snprintf(max_aspect, sizeof(max_aspect), + "%d/%d", size_hints->max_aspect.x, + size_hints->max_aspect.y); + AddToList("Maximum aspect ratio:", + max_aspect); + } /* end aspect ratio */ + XFree(size_hints); + } /* end getsizehints worked */ + } + } } -void freelist(void) +void +freelist(void) { - struct Item* cur = itemlistRoot, *cur2; - - while(cur != NULL) - { - cur2 = cur; - cur = cur->next; - free(cur2); - } -} + struct Item *cur = itemlistRoot, *cur2; + while (cur != NULL) { + cur2 = cur; + cur = cur->next; + free(cur2); + } +} -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"FvwmInitBanner: can't %s %s\n", a,b); + fprintf(stderr, "FvwmInitBanner: can't %s %s\n", a, b); } /**************************************************************************** @@ -807,25 +763,18 @@ void nocolor(char *a, char *b) * Loads a single color * ****************************************************************************/ -Pixel GetColor(char *name) +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(dpy,Root,&attributes); - color.pixel = 0; - if (!XParseColor (dpy, attributes.colormap, name, &color)) - { - nocolor("parse",name); - } - else if(!XAllocColor (dpy, attributes.colormap, &color)) - { - nocolor("alloc",name); - } - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(dpy, Root, &attributes); + color.pixel = 0; + if (!XParseColor(dpy, attributes.colormap, name, &color)) { + nocolor("parse", name); + } else if (!XAllocColor(dpy, attributes.colormap, &color)) { + nocolor("alloc", name); + } + return color.pixel; } - - - - - Index: fvwm/modules/FvwmIdent/FvwmIdent.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIdent/FvwmIdent.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIdent/FvwmIdent.h --- fvwm/modules/FvwmIdent/FvwmIdent.h +++ fvwm/modules/FvwmIdent/FvwmIdent.h @@ -1,50 +1,47 @@ -#include "../../libs/fvwmlib.h" -#define STICKY (1<<2) /* Does window stick to glass? */ -#define ONTOP (1<<1) /* does window stay on top */ -#define BORDER (1<<13) /* Is this decorated with border*/ -#define TITLE (1<<14) /* Is this decorated with title */ -#define ICONIFIED (1<<16) /* is it an icon now? */ -#define TRANSIENT (1<<17) /* is it a transient window? */ -struct target_struct -{ - char res[256]; - char class[256]; - char name[256]; - char icon_name[256]; - unsigned long id; - unsigned long frame; - long frame_x; - long frame_y; - long frame_w; - long frame_h; - long base_w; - long base_h; - long width_inc; - long height_inc; - long desktop; - unsigned long gravity; - unsigned long flags; - long title_h; - long border_w; +#include "../../libs/fvwmlib.h" +#define STICKY (1 << 2) /* Does window stick to glass? */ +#define ONTOP (1 << 1) /* does window stay on top */ +#define BORDER (1 << 13) /* Is this decorated with border*/ +#define TITLE (1 << 14) /* Is this decorated with title */ +#define ICONIFIED (1 << 16) /* is it an icon now? */ +#define TRANSIENT (1 << 17) /* is it a transient window? */ +struct target_struct { + char res[256]; + char class[256]; + char name[256]; + char icon_name[256]; + unsigned long id; + unsigned long frame; + long frame_x; + long frame_y; + long frame_w; + long frame_h; + long base_w; + long base_h; + long width_inc; + long height_inc; + long desktop; + unsigned long gravity; + unsigned long flags; + long title_h; + long border_w; }; -struct Item -{ - char* col1; - char* col2; - struct Item* next; +struct Item { + char *col1; + char *col2; + struct Item *next; }; /************************************************************************* * * Subroutine Prototypes - * + * *************************************************************************/ void Loop(int *fd); -void SendInfo(int *fd,char *message,unsigned long window); -char *safemalloc(int length); +void SendInfo(int *fd, char *message, unsigned long window); void DeadPipe(int nonsense); -void process_message(unsigned long type,unsigned long *body); +void process_message(unsigned long type, unsigned long *body); void GetTargetWindow(Window *app_win); void RedrawWindow(void); void change_window_name(char *str); @@ -62,4 +59,3 @@ void list_icon_name(unsigned long *body); void list_class(unsigned long *body); void list_res_name(unsigned long *body); void list_end(void); - Index: fvwm/modules/FvwmM4/FvwmM4.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmM4/FvwmM4.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmM4/FvwmM4.1 --- fvwm/modules/FvwmM4/FvwmM4.1 +++ fvwm/modules/FvwmM4/FvwmM4.1 @@ -14,70 +14,56 @@ .if n .sp 1 .if t .sp .5 .. -.TH FvwmM4 1 12/12/94 2.0 +.TH FVWMM4 1 "December 12, 1994" "2.0" "FVWM Modules" .UC .SH NAME FvwmM4 \- the FVWM M4 pre-processor .SH SYNOPSIS FvwmM4 is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION When called, this module will attempt to have M4 pre-process the file specified in its invocation, and then have fvwm read the resulting file. - .SH INVOCATION -FvwmM4 can be invoked by inserting the line 'FvwmM4' in -the .fvwmrc file. It can also be called from a menu or mouse binding. +FvwmM4 can be invoked by inserting the line "FvwmM4" in the .fvwmrc file. +It can also be called from a menu or mouse binding. If the user wants his entire .fvwmrc file pre-processed with FvwmM4, then fvwm should be invoked as: - .EX fvwm2 -cmd "FvwmM4 .fvwmrc" .EE - -Note that the argument to the option "-cmd" should be enclosed -in quotes, and no other quoting should be used. For example, a -typical invocation might be: - +.PP +Note that the argument to the option "-cmd" should be enclosed in quotes, +and no other quoting should be used. For example, a typical invocation might be: .EX fvwm2 -cmd "FvwmM4 -m4-squote { -m4-equote } .fvwmrc" .EE - +.PP Some options can be specified on the command line: .IP -m4-prefix I think this makes all the m4 directives require the prefix "m4_". - .TP -m4opt \fIoption\fP Lets you pass an option to the m4 program. Not really needed as any unknown options will be passed on automatically. - .TP -m4-squote \fIcharacter\fP Lets you change the m4 start-of-quote character to \fIcharacter\fP. - .TP -m4-equote \fIcharacter\fP Lets you change the m4 end-of-quote character to \fIcharacter\fP. - .TP -m4prog \fIname\fP Instead of invoking "m4", fvwm will invoke \fIname\fP. - .TP -outfile \fIfilename\fP Instead of creating a random unique name for the temporary file for the preprocessed rc file, this option will let you specify the name of the temporary file it will create. - .IP -debug -Causes the temporary file create by m4 to -be retained. This file is usually called "/tmp/fvwmrcXXXXXXXXXX" - - +Causes the temporary file create by m4 to be retained. +This file is usually called "/tmp/fvwmrcXXXXXXXXXX". .SH CONFIGURATION OPTIONS FvwmM4 defines some values for use in the pre-processor file: - .IP TWM_TYPE Always set to "fvwm". .IP SERVERHOST @@ -107,7 +93,7 @@ Some distance/pixel measurement for the horizontal direction, I think. .IP Y_RESOLUTION Some distance/pixel measurement for the vertical direction, I think. .IP PLANES -Number of color planes for the X server display +Number of color planes for the X server display. .IP BITS_PER_RGB Number of bits in each rgb triplet. .IP CLASS @@ -122,9 +108,7 @@ configure.h at compile time. .IP FVWM_MODULEDIR The directory where fvwm looks for .fvwmrc and modules by default, as determined at compile time. - .SH EXAMPLE PROLOG - .EX define(TWM_TYPE,``fvwm'')dnl define(SERVERHOST,``spx20'')dnl @@ -149,7 +133,6 @@ define(FVWM_VERSION,``1.24l'')dnl define(OPTIONS,``SHAPE XPM M4 '')dnl define(FVWM_MODULEDIR,``/local/homes/dsp/nation/modules'')dnl .EE - .SH AUTHOR FvwmM4 is the result of a random bit mutation on a hard disk, -presumably a result of a cosmic-ray or some such thing. +presumably a result of a cosmic-ray or some such thing. Index: fvwm/modules/FvwmM4/FvwmM4.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmM4/FvwmM4.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmM4/FvwmM4.c --- fvwm/modules/FvwmM4/FvwmM4.c +++ fvwm/modules/FvwmM4/FvwmM4.c @@ -3,43 +3,43 @@ * by Robert Nation * * Copyright 1994, Robert Nation - * No guarantees or warantees or anything + * No guarantees or warantees or anything * are provided or implied in any way whatsoever. Use this program at your * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ #define TRUE 1 -#define FALSE 0 +#define FALSE 0 -#include "config.h" +#include "FvwmM4.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include #include -#include +#include +#include +#include +#include +#include +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "../../fvwm/module.h" - -#include "FvwmM4.h" #include "../../libs/fvwmlib.h" -#include -#include +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" #define Resolution(pixels, mm) ((((pixels) * 100000 / (mm)) + 50) / 100) char *MyName; @@ -49,20 +49,21 @@ int ScreenWidth, ScreenHeight; int Mscreen; long Vx, Vy; -static char *MkDef(char *name, char *def); -static char *MkNum(char *name,int def); -static char *m4_defs(Display *display, const char *host, char *m4_options, char *config_file); +static char *MkDef(const char *name, const char *def); +static char *MkNum(const char *name, int def); +static char *m4_defs( + Display *display, const char *host, char *m4_options, char *config_file); #define MAXHOSTNAME 255 #define EXTRA 50 -int m4_enable; /* use m4? */ -int m4_prefix; /* Do GNU m4 prefixing (-P) */ -char m4_options[BUFSIZ]; /* Command line options to m4 */ -char m4_outfile[BUFSIZ] = ""; /* The output filename for m4 */ -char *m4_prog = "m4"; /* Name of the m4 program */ -int m4_default_quotes; /* Use default m4 quotes */ -char *m4_startquote = "`"; /* Left quote characters for m4 */ -char *m4_endquote = "'"; /* Right quote characters for m4 */ +int m4_enable; /* use m4? */ +int m4_prefix; /* Do GNU m4 prefixing (-P) */ +char m4_options[BUFSIZ]; /* Command line options to m4 */ +char m4_outfile[BUFSIZ] = ""; /* The output filename for m4 */ +char *m4_prog = "m4"; /* Name of the m4 program */ +int m4_default_quotes; /* Use default m4 quotes */ +char *m4_startquote = "`"; /* Left quote characters for m4 */ +char *m4_endquote = "'"; /* Right quote characters for m4 */ /*********************************************************************** * @@ -71,323 +72,303 @@ char *m4_endquote = "'"; /* Right quote characters for m4 */ * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - Display *dpy; /* which display are we talking to */ - char *temp, *s; - char *display_name = NULL; - char *filename = NULL; - char *tmp_file, read_string[80],delete_string[80]; - int i,m4_debug = 0; - - m4_enable = TRUE; - m4_prefix = FALSE; - strcpy(m4_options,""); - m4_default_quotes = 1; - - /* Record the program name for error messages */ - temp = argv[0]; - - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - - if(argc < 6) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - fprintf(stderr,"Wanted argc == 6. Got %d\n",argc); - exit(1); - } - - /* Open the X display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - - - Mscreen= DefaultScreen(dpy); - ScreenHeight = DisplayHeight(dpy,Mscreen); - ScreenWidth = DisplayWidth(dpy,Mscreen); - - /* We should exit if our fvwm pipes die */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - for(i=6;i %s\n", m4_prog, m4_options, + tmp_name); + else + snprintf(options, sizeof(options), "%s %s > %s\n", m4_prog, + m4_options, tmp_name); + tmpf = popen(options, "w"); + if (tmpf == NULL) { + perror("Cannot open pipe to m4"); + exit(0377); + } + gethostname(client, MAXHOSTNAME); -static char *m4_defs(Display *display, const char *host, char *m4_options, char *config_file) -{ - Screen *screen; - Visual *visual; - char client[MAXHOSTNAME], server[MAXHOSTNAME], *colon; - char ostype[BUFSIZ]; - char options[BUFSIZ]; - static char tmp_name[BUFSIZ]; - struct hostent *hostname; - char *vc; /* Visual Class */ - FILE *tmpf; - int fd; - struct passwd *pwent; - /* Generate a temporary filename. Honor the TMPDIR environment variable, - if set. Hope nobody deletes this file! */ - - if (strlen(m4_outfile) == 0) { - if ((vc=getenv("TMPDIR"))) { - strlcpy(tmp_name, vc, sizeof(tmp_name)); - } else { - strlcpy(tmp_name, "/tmp",sizeof(tmp_name)); - } - strlcat(tmp_name, "/fvwmrcXXXXXXXXXX",sizeof(tmp_name)); - mktemp(tmp_name); - } else { - strlcpy(tmp_name,m4_outfile,sizeof(tmp_name)); - } - - if (*tmp_name == '\0') - { - perror("mktemp failed in m4_defs"); - exit(0377); - } - - /* - ** check to make sure it doesn't exist already, to prevent security hole - */ - if ((fd = open(tmp_name, O_WRONLY|O_EXCL|O_CREAT, 0600)) < 0) - { - perror("exclusive open for output file failed in m4_defs"); - exit(0377); - } - close(fd); - - /* - * Create the appropriate command line to run m4, and - * open a pipe to the command. - */ - - if(m4_prefix) - sprintf(options, "%s --prefix-builtins %s > %s\n", - m4_prog, - m4_options, tmp_name); - else - sprintf(options, "%s %s > %s\n", - m4_prog, - m4_options, tmp_name); - tmpf = popen(options, "w"); - if (tmpf == NULL) { - perror("Cannot open pipe to m4"); - exit(0377); - } - - gethostname(client,MAXHOSTNAME); - - getostype (ostype, sizeof ostype); - - /* Change the quoting characters, if specified */ - - if (!m4_default_quotes) - { - fprintf(tmpf, "%schangequote(%s, %s)%sdnl\n", - (m4_prefix) ? "m4_" : "", - m4_startquote, m4_endquote, - (m4_prefix) ? "m4_" : ""); - } - - hostname = gethostbyname(client); - strlcpy(server, XDisplayName(host),sizeof(server)); - colon = strchr(server, ':'); - if (colon != NULL) *colon = '\0'; - if ((server[0] == '\0') || (!strcmp(server, "unix"))) - strlcpy(server, client, sizeof(server)); /* must be connected to :0 or unix:0 */ - - /* TWM_TYPE is fvwm, for completeness */ - - fputs(MkDef("TWM_TYPE", "fvwm"), tmpf); - - /* The machine running the X server */ - fputs(MkDef("SERVERHOST", server), tmpf); - /* The machine running the window manager process */ - fputs(MkDef("CLIENTHOST", client), tmpf); - if (hostname) - fputs(MkDef("HOSTNAME", (char *)hostname->h_name), tmpf); - else - fputs(MkDef("HOSTNAME", (char *)client), tmpf); - - fputs(MkDef("OSTYPE", ostype), tmpf); - - pwent=getpwuid(geteuid()); - fputs(MkDef("USER", pwent->pw_name), tmpf); - - fputs(MkDef("HOME", getenv("HOME")), tmpf); - fputs(MkNum("VERSION", ProtocolVersion(display)), tmpf); - fputs(MkNum("REVISION", ProtocolRevision(display)), tmpf); - fputs(MkDef("VENDOR", ServerVendor(display)), tmpf); - fputs(MkNum("RELEASE", VendorRelease(display)), tmpf); - screen = ScreenOfDisplay(display, Mscreen); - visual = DefaultVisualOfScreen(screen); - fputs(MkNum("WIDTH", DisplayWidth(display,Mscreen)), tmpf); - fputs(MkNum("HEIGHT", DisplayHeight(display,Mscreen)), tmpf); - - fputs(MkNum("X_RESOLUTION",Resolution(screen->width,screen->mwidth)),tmpf); - fputs(MkNum("Y_RESOLUTION",Resolution(screen->height,screen->mheight)),tmpf); - fputs(MkNum("PLANES",DisplayPlanes(display, Mscreen)), tmpf); - - fputs(MkNum("BITS_PER_RGB", visual->bits_per_rgb), tmpf); - fputs(MkNum("SCREEN", Mscreen), tmpf); - - switch(visual->class) - { - case(StaticGray): - vc = "StaticGray"; - break; - case(GrayScale): - vc = "GrayScale"; - break; - case(StaticColor): - vc = "StaticColor"; - break; - case(PseudoColor): - vc = "PseudoColor"; - break; - case(TrueColor): - vc = "TrueColor"; - break; - case(DirectColor): - vc = "DirectColor"; - break; - default: - vc = "NonStandard"; - break; - } - - fputs(MkDef("CLASS", vc), tmpf); - if (visual->class != StaticGray && visual->class != GrayScale) - fputs(MkDef("COLOR", "Yes"), tmpf); - else - fputs(MkDef("COLOR", "No"), tmpf); - fputs(MkDef("FVWM_VERSION", VERSION), tmpf); - - /* Add options together */ - *options = '\0'; -#ifdef SHAPE - strcat(options, "SHAPE "); -#endif -#ifdef XPM - strcat(options, "XPM "); -#endif + getostype(ostype, sizeof ostype); - strcat(options, "M4 "); + /* Change the quoting characters, if specified */ -#ifdef NO_SAVEUNDERS - strcat(options, "NO_SAVEUNDERS "); -#endif + if (!m4_default_quotes) { + fprintf(tmpf, "%schangequote(%s, %s)%sdnl\n", + (m4_prefix) ? "m4_" : "", m4_startquote, m4_endquote, + (m4_prefix) ? "m4_" : ""); + } - fputs(MkDef("OPTIONS", options), tmpf); + hostname = gethostbyname(client); + strlcpy(server, XDisplayName(host), sizeof(server)); + colon = strchr(server, ':'); + if (colon != NULL) + *colon = '\0'; + if ((server[0] == '\0') || (!strcmp(server, "unix"))) + strlcpy(server, client, + sizeof(server)); /* must be connected to :0 or unix:0 */ + + /* TWM_TYPE is fvwm, for completeness */ + + fputs(MkDef("TWM_TYPE", "fvwm"), tmpf); + + /* The machine running the X server */ + fputs(MkDef("SERVERHOST", server), tmpf); + /* The machine running the window manager process */ + fputs(MkDef("CLIENTHOST", client), tmpf); + if (hostname) + fputs(MkDef("HOSTNAME", (char *)hostname->h_name), tmpf); + else + fputs(MkDef("HOSTNAME", (char *)client), tmpf); + + fputs(MkDef("OSTYPE", ostype), tmpf); + + pwent = getpwuid(geteuid()); + fputs(MkDef("USER", pwent->pw_name), tmpf); + + fputs(MkDef("HOME", getenv("HOME")), tmpf); + fputs(MkNum("VERSION", ProtocolVersion(display)), tmpf); + fputs(MkNum("REVISION", ProtocolRevision(display)), tmpf); + fputs(MkDef("VENDOR", ServerVendor(display)), tmpf); + fputs(MkNum("RELEASE", VendorRelease(display)), tmpf); + screen = ScreenOfDisplay(display, Mscreen); + visual = DefaultVisualOfScreen(screen); + fputs(MkNum("WIDTH", DisplayWidth(display, Mscreen)), tmpf); + fputs(MkNum("HEIGHT", DisplayHeight(display, Mscreen)), tmpf); + + fputs(MkNum("X_RESOLUTION", Resolution(screen->width, screen->mwidth)), + tmpf); + fputs( + MkNum("Y_RESOLUTION", Resolution(screen->height, screen->mheight)), + tmpf); + fputs(MkNum("PLANES", DisplayPlanes(display, Mscreen)), tmpf); + + fputs(MkNum("BITS_PER_RGB", visual->bits_per_rgb), tmpf); + fputs(MkNum("SCREEN", Mscreen), tmpf); + + switch (visual->class) { + case (StaticGray): + vc = "StaticGray"; + break; + case (GrayScale): + vc = "GrayScale"; + break; + case (StaticColor): + vc = "StaticColor"; + break; + case (PseudoColor): + vc = "PseudoColor"; + break; + case (TrueColor): + vc = "TrueColor"; + break; + case (DirectColor): + vc = "DirectColor"; + break; + default: + vc = "NonStandard"; + break; + } - fputs(MkDef("FVWM_MODULEDIR", FVWM_MODULEDIR), tmpf); - fputs(MkDef("FVWM_CONFIGDIR", FVWM_CONFIGDIR), tmpf); + fputs(MkDef("CLASS", vc), tmpf); + if (visual->class != StaticGray && visual->class != GrayScale) + fputs(MkDef("COLOR", "Yes"), tmpf); + else + fputs(MkDef("COLOR", "No"), tmpf); + fputs(MkDef("FVWM_VERSION", VERSION), tmpf); + + /* Add options together */ + options[0] = '\0'; +#ifdef SHAPE + strlcat(options, "SHAPE ", sizeof(options)); +#endif +#ifdef XPM + strlcat(options, "XPM ", sizeof(options)); +#endif - /* - * At this point, we've sent the definitions to m4. Just include - * the fvwmrc file now. - */ + strlcat(options, "M4 ", sizeof(options)); - fprintf(tmpf, "%sinclude(%s%s%s)\n", - (m4_prefix) ? "m4_": "", - m4_startquote, - config_file, - m4_endquote); +#ifdef NO_SAVEUNDERS + strlcat(options, "NO_SAVEUNDERS ", sizeof(options)); +#endif - pclose(tmpf); - return(tmp_name); -} + fputs(MkDef("OPTIONS", options), tmpf); + fputs(MkDef("FVWM_MODULEDIR", FVWM_MODULEDIR), tmpf); + fputs(MkDef("FVWM_CONFIGDIR", FVWM_CONFIGDIR), tmpf); + /* + * At this point, we've sent the definitions to m4. Just include + * the fvwmrc file now. + */ + fprintf(tmpf, "%sinclude(%s%s%s)\n", (m4_prefix) ? "m4_" : "", + m4_startquote, config_file, m4_endquote); + pclose(tmpf); + return (tmp_name); +} /*********************************************************************** * @@ -395,77 +376,56 @@ static char *m4_defs(Display *display, const char *host, char *m4_options, char * SIGPIPE handler - SIGPIPE means fvwm is dying * ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(0); + exit(0); } - - -static char *MkDef(char *name, char *def) +static char * +MkDef(const char *name, const char *def) { - static char *cp = NULL; - static int maxsize = 0; - int n; - - /* The char * storage only lasts for 1 call... */ - - /* Get space to hold everything, if needed */ - - n = EXTRA + strlen(name) + strlen(def); - if (n > maxsize) { - maxsize = n; - if (cp == NULL) { - cp = malloc(n); - } else { - cp = realloc(cp, n); + static char *cp = NULL; + static int maxsize = 0; + int needed; + const char *prefix = m4_prefix ? "m4_define" : "define"; + const char *suffix = m4_prefix ? "m4_" : ""; + + needed = snprintf(NULL, 0, "%s(%s,%s%s%s%s%s)%sdnl\n", prefix, name, + m4_startquote, m4_startquote, def, m4_endquote, m4_endquote, + suffix); + if (needed < 0) { + perror("MkDef failed to calculate length"); + exit(0377); + } + needed += 1; /* account for terminating null */ + if (needed > maxsize) { + char *tmp = realloc(cp, needed); + if (tmp == NULL) { + perror("MkDef can't allocate enough space for a macro " + "definition"); + free(cp); + exit(0377); + } + cp = tmp; + maxsize = needed; } - } - - if (cp == NULL) { - perror("MkDef can't allocate enough space for a macro definition"); - exit(0377); - } - - /* Create the macro definition, using the appropriate prefix, if any */ - - if (m4_prefix) - { - strcpy(cp, "m4_define("); - } - else - strcpy(cp, "define("); - - strcat(cp, name); - - /* Tack on "," and 2 sets of starting quotes */ - strcat(cp, ","); - strcat(cp, m4_startquote); - strcat(cp, m4_startquote); - - /* The definition itself */ - strcat(cp, def); - - /* Add 2 sets of closing quotes */ - strcat(cp, m4_endquote); - strcat(cp, m4_endquote); - - /* End the definition, appropriately */ - strcat(cp, ")"); - if (m4_prefix) - { - strcat(cp, "m4_"); - } - strcat(cp, "dnl\n"); + if (snprintf(cp, maxsize, "%s(%s,%s%s%s%s%s)%sdnl\n", prefix, name, + m4_startquote, m4_startquote, def, m4_endquote, m4_endquote, + suffix) < 0) { + perror("MkDef failed to build macro definition"); + exit(0377); + } - return(cp); + return (cp); } -static char *MkNum(char *name,int def) +static char * +MkNum(const char *name, int def) { - char num[20]; + char num[20]; - sprintf(num, "%d", def); - return(MkDef(name, num)); + snprintf(num, sizeof(num), "%d", def); + return (MkDef(name, num)); } Index: fvwm/modules/FvwmM4/FvwmM4.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmM4/FvwmM4.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmM4/FvwmM4.h --- fvwm/modules/FvwmM4/FvwmM4.h +++ fvwm/modules/FvwmM4/FvwmM4.h @@ -3,10 +3,6 @@ /************************************************************************* * * Subroutine Prototypes - * + * *************************************************************************/ void DeadPipe(int nonsense); - - - - Index: fvwm/modules/FvwmPager/FvwmPager.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmPager/FvwmPager.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmPager/FvwmPager.1 --- fvwm/modules/FvwmPager/FvwmPager.1 +++ fvwm/modules/FvwmPager/FvwmPager.1 @@ -1,25 +1,28 @@ .\" $OpenBSD: FvwmPager.1,v 1.1.1.1 2006/11/26 10:53:52 matthieu Exp $ .\" t -.\" @(#)FvwmPager.1 1/12/94 -.TH FvwmPager 1 "Mar 16 1994" 1.20 +.\" @(#)FvwmPager.1 1/12/94 +.TH FVWMPAGER 1 "March 16, 1994" "1.20" "FVWM Modules" .UC .SH NAME FvwmPager \- the FVWM Pager module .SH SYNOPSIS FvwmPager is spawned by fvwm, so no command line invocation will work. +.PP From within the .fvwmrc file, FvwmPager is spawned as follows: .nf .sp Module FvwmPager 0 3 .sp .fi -or +.PP +Alternatively: .nf .sp Module FvwmPager * * .sp .fi -or from within an fvwm pop-up menu: +.PP +From within an fvwm pop-up menu: .nf .sp AddToMenu Module-Popup "Modules" Title @@ -31,47 +34,45 @@ AddToMenu Module-Popup "Modules" Title + "Pager" Module FvwmPager 0 3 .sp .fi -or +.PP +Alternatively: .nf .sp + "Pager" Module FvwmPager * * .sp .fi -where "0" is the first desktop to show, and "3" is the last and -"*" is the current dektop. In the second format (with two asterisks) -the current desk is always visible in the pager (and it is also the -only one). - +.PP +Here, "0" is the first desktop to show, and "3" is the last and "*" +is the current dektop. In the second format (with two asterisks) the +current desk is always visible in the pager (and it is also the only one). .SH DESCRIPTION The FvwmPager module shows a miniature view of the Fvwm desktops which are specified in the command line. This is a useful reminder of where your active windows are. Windows in the pager are shown in the same -color as their fvwm decorations. - -The pager can be used to change your viewport into the current -desktop, to change desktops, or to move windows around. - -Pressing mouse button 1 in the pager will cause you viewport to -change to the selected page of the selected desk. If you click with -button 1 in the desk-label area, you will switch desks but not -pages within the desk. - -Dragging mouse button 2 on a miniature view of a window will cause -that window to be move to the location where you release the mouse -button, but your viewport will not change. If you drag the window -out of the pager and onto your desktop, a full size image of -the window will appear for you to place. There is no way to -pick up a full size image of the window and move it into the pager, -however. Since some mice do not have button 2, I have made provisions to drag -windows in the pager by using pressing modifier-1 (usually Alt) and dragging -with button 3. - -Clicking mouse button 3 on a location will cause the viewport to move -to the selected location and switch desks if necessary, but will not -align the viewport to a page boundary. Dragging button 3 will -cause the viewport to move as you drag but not switch desktops, even -if the pointer moves to another desktop. - +color as their fvwm decorations. +.PP +The pager can be used to change your viewport into the current desktop, +to change desktops, or to move windows around. +.PP +Pressing mouse button 1 in the pager will cause you viewport to change +to the selected page of the selected desk. If you click with button 1 in +the desk-label area, you will switch desks but not pages within the desk. +.PP +Dragging mouse button 2 on a miniature view of a window will cause that +window to be move to the location where you release the mouse button, +but your viewport will not change. If you drag the window out of the +pager and onto your desktop, a full size image of the window will appear +for you to place. There is no way to pick up a full size image of the +window and move it into the pager, however. Since some mice do not have +button 2, I have made provisions to drag windows in the pager by pressing +modifier-1 (usually Alt) and dragging with button 3. +.PP +Clicking mouse button 3 on a location will cause the viewport to move to +the selected location and switch desks if necessary, but will not align +the viewport to a page boundary. Dragging button 3 will cause the +viewport to move as you drag but not switch desktops, even if the pointer +moves to another desktop. +.PP When iconified, the pager will work as a fully functional current page only pager. Windows and viewports can be moved within the icon of the pager. Users will want to make sure that they have no lines similar to @@ -81,92 +82,71 @@ Icon "Fvwm Pager" whatever .sp .fi in their .fvwmrc files. - - .SH COPYRIGHTS -The FvwmPager program, and the concept for -interfacing this module to the Window Manager, are all original work -by Robert Nation. - -Copyright 1994, Robert Nation. No guarantees or warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - - +The FvwmPager program, and the concept for interfacing this module to the +Window Manager, are original work by Robert Nation. +.PP +Copyright 1994, Robert Nation. No guarantees or warranties or anything are +provided or implied in any way whatsoever. Use this program at your own risk. +Permission to use this program for any purpose is given, as long as the +copyright is kept intact. .SH INITIALIZATION -During initialization, \fIFvwmPager\fP will eventually search a -configuration file which describes the time-outs and actions to take. -The configuration file is the same file that fvwm used during initialization. - -If the FvwmPager executable is linked to another name, ie ln -s -FvwmPager OtherPager, then another module called OtherPager can be -started, with a completely different configuration than FvwmPager, -simply by changing the keyword FvwmPager to OtherPager. This way multiple -pager programs can be used. - +During initialization, \fIFvwmPager\fP will eventually search a configuration +file which describes the time-outs and actions to take. The configuration file +is the same file that fvwm used during initialization. +.PP +If the FvwmPager executable is linked to another name, ie ln -s FvwmPager +OtherPager, then another module called OtherPager can be started, with a +completely different configuration than FvwmPager, simply by changing the +keyword FvwmPager to OtherPager. This way multiple pager programs can be used. .SH KEYBOARD FOCUS CONTROL -You can direct the keyboard focus to any window on the current desktop -by clicking with button 2 on its image in the pager. The window does -not need to be visible, but it does need to be on the current page. - +You can direct the keyboard focus to any window on the current desktop by +clicking with button 2 on its image in the pager. The window does not need to +be visible, but it does need to be on the current page. .SH INVOCATION -The invocation method was shown in the synopsis section - +The invocation method was shown in the synopsis section. .SH CONFIGURATION OPTIONS -FvwmPager reads the same .fvwmrc file as fvwm reads when it starts up, -and looks for certain configuration options: - +FvwmPager reads the same .fvwmrc file as fvwm reads when it starts up, and +looks for certain configuration options: .IP "*FvwmPagerGeometry \fIgeometry\fP" Completely or partially specifies the pager windows location and -geometry, in standard X11 notation. +geometry, in standard X11 notation. In order to maintain an undistorted aspect ratio, you might want to leave out either the width or height dimension of the geometry specification - .IP "*FvwmPagerRows \fIrows\fP" Tells fvwm how many rows of desks to use when laying out the pager window. - .IP "*FvwmPagerColumns \fIcolumns\fP" Tells fvwm how many columnss of desks to use when laying out the pager window. - .IP "*FvwmPagerIconGeometry \fIgeometry\fP" -Specifies a size (optional) and location (optional) for the pager's icon +Specifies a size (optional) and location (optional) for the pager's icon window. Since there is no easy way for FvwmPager to determine the height of the icon's label, you will have to make an allowance for the icon label height when using negative y-coordinates in the icon location specification (used to specify a location relative to the bottom instead of the top of the screen). - .IP "*FvwmPagerStartIconic" -Causes the pager to start iconified. - +Causes the pager to start iconified. .IP "*FvwmPagerNoStartIconic" Causes the pager to start normally. Useful for cancelling the effect of the \fIStartIconic\fP option. - .IP "*FvwmPagerFont \fIfont-name\fP" Specified a font to use to label the desktops. If \fIfont_name\fP is "none" then no desktop labels will be displayed. - .IP "*FvwmPagerSmallFont \fIfont-name\fP" Specified a font to use to label the window names in the pager. If not specified, the window labels will be omitted. Window labels seem to be fairly useless for desktop scales of 32 or greater. If \fIfont_name\fP is "none" then no window names will be displayed. - .IP "*FvwmPagerFore \fIcolor\fP" Specifies the color to use to write the desktop labels, and to draw the page-grid lines. - .IP "*FvwmPagerBack \fIcolor\fP" Specifies the background color for the window. - .IP "*FvwmPagerHilight \fIcolor\fP" The active page and desk label will be highlighted by using this background pattern instead of the normal background. - .IP "*FvwmPagerWindowColors \fIfore back hiFore hiBack\fP" Change the normal/highlight colors of the windows. \fIfore\fP and \fIhiFore\fP specify the colors as used for the font inside the windows. @@ -182,26 +162,22 @@ to desktops, i.e. *FvwmPagerLabel * Matlab .sp .fi - .IP "*FvwmPagerDeskColor \fIdesk color\fP" Assigns the color \fIcolor\fP to desk \fIdesk\fP (or the current desk if desk is "*") in the pager window. This replaces the background color for -the particular \fIdesk\fP. This only works when the pager is full sized. -When Iconified, the pager uses the color specified by *FvwmPagerBack. +the particular \fIdesk\fP. This only works when the pager is full sized. +When iconified, the pager uses the color specified by *FvwmPagerBack. .sp -\fBTIP:\fP Try using *FvwmPagerDeskColor in conjunction with +\fBTIP:\fP Try using *FvwmPagerDeskColor in conjunction with FvwmCpp (or FvwmM4) and FvwmBacker to assign identical colors to your various desktops and the pager representations. - .IP "*FvwmPagerDeskTopScale \fInumber\fP" If the geometry is not specified, then a desktop reduction factor is used to calculate the pager's size. Things in the pager window are shown at 1/\fInumber\fP of the actual size. - .IP "*FvwmPagerMiniIcons" Allow the pager to display a window's mini icon in the pager, if it has one, instead of showing the window's name. - .IP "*FvwmPagerBalloons [\fItype\fP]" Show a balloon describing the window when the pointer is moved into a window in the pager. Currently only the window's icon name is shown. @@ -209,24 +185,18 @@ If \fItype\fP is \fIPager\fP balloons are just shown for an uniconified pager; if \fItype\fP is \fIIcon\fP balloons are just shown for an iconified pager. If \fItype\fP is anything else (or null) balloons are always shown. - .IP "*FvwmPagerBalloonFore \fIcolor\fP" Specifies the color for text in the balloon window. If omitted it defaults to the foreground color for the window being described. - .IP "*FvwmPagerBalloonBack \fIcolor\fP" Specifies the background color for the balloon window. If omitted it defaults to the background color for the window being described. - .IP "*FvwmPagerBalloonFont \fIfont-name\fP" Specifies a font to use for the balloon text. Defaults to \fIfixed\fP. - .IP "*FvwmPagerBalloonBorderWidth \fInumber\fP" Sets the width of the balloon window's border. Defaults to 1. - .IP "*FvwmPagerBalloonBorderColor \fIcolor\fP" Sets the color of the balloon window's border. Defaults to black. - .IP "*FvwmPagerBalloonYOffset \fInumber\fP" The balloon window is positioned to be horizontally centered against the pager window it is describing. The vertical position may be @@ -236,10 +206,8 @@ pixels above the pager window, positive offsets of \fI+n\fP are placed direct transit from pager window to balloon window, causing an event loop. Defaults to +2. The offset will change sign automatically, as needed, to keep the balloon on the screen. - - .SH AUTHOR -Robert Nation +Robert Nation .br DeskColor patch contributed by Alan Wild .br Index: fvwm/modules/FvwmPager/FvwmPager.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmPager/FvwmPager.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmPager/FvwmPager.c --- fvwm/modules/FvwmPager/FvwmPager.c +++ fvwm/modules/FvwmPager/FvwmPager.c @@ -10,38 +10,37 @@ #define TRUE 1 #define FALSE 0 -#include "config.h" +#include +#include -#include -#include +#include +#include #include +#include +#include #include -#include -#include #include -#include -#include -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ -#endif /* Saul */ +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" + +#endif /* Saul */ #include #if HAVE_SYS_SELECT_H #include #endif +#include +#include #include -#include #include -#include -#include +#include +#include "../../fvwm/fvwm.h" #include "../../fvwm/module.h" - #include "../../libs/fvwmlib.h" #include "FvwmPager.h" -#include "../../fvwm/fvwm.h" char *MyName; int fd_width; @@ -59,8 +58,8 @@ ScreenInfo Scr; PagerWindow *Start = NULL; PagerWindow *FocusWin = NULL; -Display *dpy; /* which display are we talking to */ -int x_fd,fd_width; +Display *dpy; /* which display are we talking to */ +int x_fd, fd_width; char *PagerFore = NULL; char *PagerBack = NULL; @@ -81,27 +80,27 @@ char *BalloonBorderColor = NULL; int BalloonBorderWidth = 1; int BalloonYOffset = 2; -int window_w=0, window_h=0, window_x=0, window_y=0; -int icon_x=-10000, icon_y=-10000, icon_w=0, icon_h=0; -int usposition = 0,uselabel = 1; +int window_w = 0, window_h = 0, window_x = 0, window_y = 0; +int icon_x = -10000, icon_y = -10000, icon_w = 0, icon_h = 0; +int usposition = 0, uselabel = 1; int xneg = 0, yneg = 0; extern DeskInfo *Desks; int StartIconic = 0; int MiniIcons = 0; int Rows = -1, Columns = -1; -int desk1=0, desk2 =0; +int desk1 = 0, desk2 = 0; int ndesks = 0; Pixel win_back_pix = -1; Pixel win_fore_pix = -1; Pixel win_hi_back_pix = -1; Pixel win_hi_fore_pix = -1; char fAlwaysCurrentDesk = 0; -PagerStringList string_list = { NULL, 0, NULL, NULL }; +PagerStringList string_list = {NULL, 0, NULL, NULL}; Bool error_occured = False; static volatile sig_atomic_t isTerminated = False; -static RETSIGTYPE TerminateHandler(int); +static void TerminateHandler(int); /*********************************************************************** * @@ -109,167 +108,158 @@ static RETSIGTYPE TerminateHandler(int); * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - char *display_name = NULL; - int itemp,i; - char line[100]; - - /* Save our program name - for error messages */ - temp = argv[0]; - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName, temp); - - if(argc < 6) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - if(argc < 8) - { - fprintf(stderr,"%s Version %s requires two arguments: %s n m\n", - MyName,VERSION,MyName); - fprintf(stderr," where desktops n through m are displayed\n"); - fprintf(stderr, - " if n and m are \"*\" the current desktop is displayed\n"); - exit(1); - } + char *temp, *s; + char *display_name = NULL; + int itemp, i; + char line[100]; + + /* Save our program name - for error messages */ + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + { + size_t name_len = strlen(temp) + 1; + MyName = xmalloc(name_len); + strlcpy(MyName, temp, name_len); + } + + if (argc < 6) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); + } + if (argc < 8) { + fprintf(stderr, + "%s Version %s requires two arguments: %s n m\n", MyName, + VERSION, MyName); + fprintf( + stderr, " where desktops n through m are displayed\n"); + fprintf(stderr, " if n and m are \"*\" the current desktop " + "is displayed\n"); + exit(1); + } #ifdef HAVE_SIGACTION - { - struct sigaction sigact; - - sigemptyset(&sigact.sa_mask); -# ifdef SA_INTERRUPT - sigact.sa_flags = SA_INTERRUPT; -# else - sigact.sa_flags = 0; -# endif - sigact.sa_handler = TerminateHandler; - - sigaction(SIGPIPE, &sigact, NULL); - sigaction(SIGTERM, &sigact, NULL); - sigaction(SIGQUIT, &sigact, NULL); - sigaction(SIGINT, &sigact, NULL); - sigaction(SIGHUP, &sigact, NULL); - } + { + struct sigaction sigact; + + sigemptyset(&sigact.sa_mask); +#ifdef SA_INTERRUPT + sigact.sa_flags = SA_INTERRUPT; #else - /* We don't have sigaction(), so fall back to less robust methods. */ - signal(SIGPIPE, TerminateHandler); - signal(SIGTERM, TerminateHandler); - signal(SIGQUIT, TerminateHandler); - signal(SIGINT, TerminateHandler); - signal(SIGHUP, TerminateHandler); + sigact.sa_flags = 0; #endif + sigact.sa_handler = TerminateHandler; - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - fd_width = GetFdWidth(); - - desk1 = atoi(argv[6]); - desk2 = atoi(argv[7]); - - if(desk2 < desk1) - { - itemp = desk1; - desk1 = desk2; - desk2 = itemp; - } - ndesks = desk2 - desk1 + 1; - if (StrEquals(argv[6], "*") && StrEquals(argv[7], "*")) - { - desk1 = Scr.CurrentDesk; - desk2 = Scr.CurrentDesk; - fAlwaysCurrentDesk = 1; - } - - PagerFore = strdup("black"); - PagerBack = strdup("white"); - font_string = strdup("fixed"); - HilightC = strdup("black"); - BalloonFont = strdup("fixed"); - BalloonBorderColor = strdup("black"); - Desks = (DeskInfo *)safemalloc(ndesks*sizeof(DeskInfo)); - for(i=0;inext); - t = t->next; - i++; - } - *prev = (PagerWindow *)safemalloc(sizeof(PagerWindow)); - (*prev)->w = body[0]; - (*prev)->t = (char *)body[2]; - (*prev)->frame = body[1]; - (*prev)->x = body[3]; - (*prev)->y = body[4]; - (*prev)->width = body[5]; - (*prev)->height = body[6]; - (*prev)->desk = body[7]; - (*prev)->next = NULL; - (*prev)->flags = body[8]; - (*prev)->pager_view_width = 0; - (*prev)->pager_view_height = 0; - (*prev)->icon_view_width = 0; - (*prev)->icon_view_height = 0; - (*prev)->icon_name = NULL; - (*prev)->mini_icon.picture = 0; - (*prev)->title_height = body[9]; - (*prev)->border_width = body[10]; - (*prev)->icon_w = body[19]; - (*prev)->icon_pixmap_w = body[20]; - if ((win_fore_pix != -1) && (win_back_pix != -1)) - { - (*prev)->text = win_fore_pix; - (*prev)->back = win_back_pix; - } - else - { - (*prev)->text = body[22]; - (*prev)->back = body[23]; - } - AddNewWindow(*prev); + PagerWindow *t, **prev; + int i = 0; + + t = Start; + prev = &Start; + while (t != NULL) { + prev = &(t->next); + t = t->next; + i++; + } + *prev = (PagerWindow *)xmalloc(sizeof(PagerWindow)); + (*prev)->w = body[0]; + (*prev)->t = (char *)body[2]; + (*prev)->frame = body[1]; + (*prev)->x = body[3]; + (*prev)->y = body[4]; + (*prev)->width = body[5]; + (*prev)->height = body[6]; + (*prev)->desk = body[7]; + (*prev)->next = NULL; + (*prev)->flags = body[8]; + (*prev)->pager_view_width = 0; + (*prev)->pager_view_height = 0; + (*prev)->icon_view_width = 0; + (*prev)->icon_view_height = 0; + (*prev)->icon_name = NULL; + (*prev)->mini_icon.picture = 0; + (*prev)->title_height = body[9]; + (*prev)->border_width = body[10]; + (*prev)->icon_w = body[19]; + (*prev)->icon_pixmap_w = body[20]; + if ((win_fore_pix != -1) && (win_back_pix != -1)) { + (*prev)->text = win_fore_pix; + (*prev)->back = win_back_pix; + } else { + (*prev)->text = body[22]; + (*prev)->back = body[23]; + } + AddNewWindow(*prev); } /*********************************************************************** @@ -437,75 +421,62 @@ void list_add(unsigned long *body) * list_configure - displays packet contents to stderr * ***********************************************************************/ -void list_configure(unsigned long *body) +void +list_configure(unsigned long *body) { - PagerWindow *t; - Window target_w; - - target_w = body[0]; - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t== NULL) - { - list_add(body); - } - else - { - t->t = (char *)body[2]; - t->frame = body[1]; - t->frame_x = body[3]; - t->frame_y = body[4]; - t->frame_width = body[5]; - t->frame_height = body[6]; - t->title_height = body[9]; - t->border_width = body[10]; - t->flags = body[8]; - t->icon_w = body[19]; - t->icon_pixmap_w = body[20]; - if ((win_fore_pix != -1) && (win_back_pix != -1)) - { - t->text = win_fore_pix; - t->back = win_back_pix; - } - else - { - t->text = body[22]; - t->back = body[23]; - } - if(t->flags & ICONIFIED) - { - t->x = t->icon_x; - t->y = t->icon_y; - t->width = t->icon_width; - t->height = t->icon_height; - if(t->flags & SUPPRESSICON) - { - t->x = -10000; - t->y = -10000; - } - } - else - { - t->x = t->frame_x; - t->y = t->frame_y; - t->width = t->frame_width; - t->height = t->frame_height; + PagerWindow *t; + Window target_w; + + target_w = body[0]; + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; } - if(t->desk != body[7]) - { - ChangeDeskForWindow(t,body[7]); + if (t == NULL) { + list_add(body); + } else { + t->t = (char *)body[2]; + t->frame = body[1]; + t->frame_x = body[3]; + t->frame_y = body[4]; + t->frame_width = body[5]; + t->frame_height = body[6]; + t->title_height = body[9]; + t->border_width = body[10]; + t->flags = body[8]; + t->icon_w = body[19]; + t->icon_pixmap_w = body[20]; + if ((win_fore_pix != -1) && (win_back_pix != -1)) { + t->text = win_fore_pix; + t->back = win_back_pix; + } else { + t->text = body[22]; + t->back = body[23]; + } + if (t->flags & ICONIFIED) { + t->x = t->icon_x; + t->y = t->icon_y; + t->width = t->icon_width; + t->height = t->icon_height; + if (t->flags & SUPPRESSICON) { + t->x = -10000; + t->y = -10000; + } + } else { + t->x = t->frame_x; + t->y = t->frame_y; + t->width = t->frame_width; + t->height = t->frame_height; + } + if (t->desk != body[7]) { + ChangeDeskForWindow(t, body[7]); + } else + MoveResizePagerView(t); + if (FocusWin == t) + Hilight(t, ON); + else + Hilight(t, OFF); } - - else - MoveResizePagerView(t); - if(FocusWin == t) - Hilight(t,ON); - else - Hilight(t,OFF); - } } /*********************************************************************** @@ -514,32 +485,31 @@ void list_configure(unsigned long *body) * list_destroy - displays packet contents to stderr * ***********************************************************************/ -void list_destroy(unsigned long *body) +void +list_destroy(unsigned long *body) { - PagerWindow *t,**prev; - Window target_w; - - target_w = body[0]; - t = Start; - prev = &Start; - while((t!= NULL)&&(t->w != target_w)) - { - prev = &(t->next); - t = t->next; - } - if(t!= NULL) - { - if(prev != NULL) - *prev = t->next; - /* remove window from the chain */ - if(t->PagerView != None) - XDestroyWindow(dpy,t->PagerView); - XDestroyWindow(dpy,t->IconView); - if(FocusWin == t) - FocusWin = NULL; - - free(t); - } + PagerWindow *t, **prev; + Window target_w; + + target_w = body[0]; + t = Start; + prev = &Start; + while ((t != NULL) && (t->w != target_w)) { + prev = &(t->next); + t = t->next; + } + if (t != NULL) { + if (prev != NULL) + *prev = t->next; + /* remove window from the chain */ + if (t->PagerView != None) + XDestroyWindow(dpy, t->PagerView); + XDestroyWindow(dpy, t->IconView); + if (FocusWin == t) + FocusWin = NULL; + + free(t); + } } /*********************************************************************** @@ -548,38 +518,34 @@ void list_destroy(unsigned long *body) * list_focus - displays packet contents to stderr * ***********************************************************************/ -void list_focus(unsigned long *body) +void +list_focus(unsigned long *body) { - PagerWindow *t,*temp; - Window target_w; - extern Pixel focus_pix, focus_fore_pix; - target_w = body[0]; - - if ((win_hi_fore_pix != -1) && (win_hi_back_pix != -1)) - { - focus_pix = win_hi_back_pix; - focus_fore_pix = win_hi_fore_pix; - } - else - { - focus_pix = body[4]; - focus_fore_pix = body[3]; - } - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t != FocusWin) - { - temp = FocusWin; - FocusWin = t; - - if(temp != NULL) - Hilight(temp,OFF); - if(FocusWin != NULL) - Hilight(FocusWin,ON); - } + PagerWindow *t, *temp; + Window target_w; + extern Pixel focus_pix, focus_fore_pix; + target_w = body[0]; + + if ((win_hi_fore_pix != -1) && (win_hi_back_pix != -1)) { + focus_pix = win_hi_back_pix; + focus_fore_pix = win_hi_fore_pix; + } else { + focus_pix = body[4]; + focus_fore_pix = body[3]; + } + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; + } + if (t != FocusWin) { + temp = FocusWin; + FocusWin = t; + + if (temp != NULL) + Hilight(temp, OFF); + if (FocusWin != NULL) + Hilight(FocusWin, ON); + } } /*********************************************************************** @@ -588,21 +554,21 @@ void list_focus(unsigned long *body) * list_new_page - displays packet contents to stderr * ***********************************************************************/ -void list_new_page(unsigned long *body) +void +list_new_page(unsigned long *body) { - Scr.Vx = (long)body[0]; - Scr.Vy = (long)body[1]; - Scr.CurrentDesk = (long)body[2]; - if((Scr.VxMax != body[3])||(Scr.VyMax != body[4])) - { - Scr.VxMax = body[3]; - Scr.VyMax = body[4]; - ReConfigure(); - } - MovePage(); - MoveStickyWindows(); - Hilight(FocusWin,OFF); - Hilight(FocusWin,ON); + Scr.Vx = (long)body[0]; + Scr.Vy = (long)body[1]; + Scr.CurrentDesk = (long)body[2]; + if ((Scr.VxMax != body[3]) || (Scr.VyMax != body[4])) { + Scr.VxMax = body[3]; + Scr.VyMax = body[4]; + ReConfigure(); + } + MovePage(); + MoveStickyWindows(); + Hilight(FocusWin, OFF); + Hilight(FocusWin, ON); } /*********************************************************************** @@ -611,67 +577,59 @@ void list_new_page(unsigned long *body) * list_new_desk - displays packet contents to stderr * ***********************************************************************/ -void list_new_desk(unsigned long *body) +void +list_new_desk(unsigned long *body) { - int oldDesk; - - oldDesk = Scr.CurrentDesk; - Scr.CurrentDesk = (long)body[0]; - if (fAlwaysCurrentDesk && oldDesk != Scr.CurrentDesk) - { - PagerWindow *t; - PagerStringList *item; - char line[100]; - - desk1 = Scr.CurrentDesk; - desk2 = Scr.CurrentDesk; - for (t = Start; t != NULL; t = t->next) - { - if (t->desk == oldDesk || t->desk == Scr.CurrentDesk) - ChangeDeskForWindow(t, t->desk); - } - item = FindDeskStrings(Scr.CurrentDesk); - if (Desks[0].label != NULL) - { - free(Desks[0].label); - Desks[0].label = NULL; - } - if (item->next != NULL && item->next->label != NULL) - { - CopyString(&Desks[0].label, item->next->label); - } - else - { - sprintf(line, "Desk %d", desk1); - CopyString(&Desks[0].label, line); - } - XStoreName(dpy, Scr.Pager_w, Desks[0].label); - XSetIconName(dpy, Scr.Pager_w, Desks[0].label); - if (Desks[0].Dcolor != NULL) - { - free(Desks[0].Dcolor); - Desks[0].Dcolor = NULL; - } - if (item->next != NULL && item->next->Dcolor != NULL) - { - CopyString(&Desks[0].Dcolor, item->next->Dcolor); - } - else - { - /* Use default title if not specified by user. */ - CopyString(&Desks[0].Dcolor, PagerBack); + int oldDesk; + + oldDesk = Scr.CurrentDesk; + Scr.CurrentDesk = (long)body[0]; + if (fAlwaysCurrentDesk && oldDesk != Scr.CurrentDesk) { + PagerWindow *t; + PagerStringList *item; + char line[100]; + + desk1 = Scr.CurrentDesk; + desk2 = Scr.CurrentDesk; + for (t = Start; t != NULL; t = t->next) { + if (t->desk == oldDesk || t->desk == Scr.CurrentDesk) + ChangeDeskForWindow(t, t->desk); + } + item = FindDeskStrings(Scr.CurrentDesk); + if (Desks[0].label != NULL) { + free(Desks[0].label); + Desks[0].label = NULL; + } + if (item->next != NULL && item->next->label != NULL) { + CopyString(&Desks[0].label, item->next->label); + } else { + snprintf(line, sizeof(line), "Desk %d", desk1); + CopyString(&Desks[0].label, line); + } + XStoreName(dpy, Scr.Pager_w, Desks[0].label); + XSetIconName(dpy, Scr.Pager_w, Desks[0].label); + if (Desks[0].Dcolor != NULL) { + free(Desks[0].Dcolor); + Desks[0].Dcolor = NULL; + } + if (item->next != NULL && item->next->Dcolor != NULL) { + CopyString(&Desks[0].Dcolor, item->next->Dcolor); + } else { + /* Use default title if not specified by user. */ + CopyString(&Desks[0].Dcolor, PagerBack); + } + XSetWindowBackground( + dpy, Desks[0].w, GetColor(Desks[0].Dcolor)); + XClearWindow(dpy, Desks[0].w); } - XSetWindowBackground(dpy, Desks[0].w, GetColor(Desks[0].Dcolor)); - XClearWindow(dpy, Desks[0].w); - } - MovePage(); + MovePage(); - DrawGrid(oldDesk - desk1,1); - DrawGrid(Scr.CurrentDesk - desk1,1); - MoveStickyWindows(); - Hilight(FocusWin,OFF); - Hilight(FocusWin,ON); + DrawGrid(oldDesk - desk1, 1); + DrawGrid(Scr.CurrentDesk - desk1, 1); + MoveStickyWindows(); + Hilight(FocusWin, OFF); + Hilight(FocusWin, ON); } /*********************************************************************** @@ -680,25 +638,23 @@ void list_new_desk(unsigned long *body) * list_raise - displays packet contents to stderr * ***********************************************************************/ -void list_raise(unsigned long *body) +void +list_raise(unsigned long *body) { - PagerWindow *t; - Window target_w; - - target_w = body[0]; - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t!= NULL) - { - if(t->PagerView != None) - XRaiseWindow(dpy,t->PagerView); - XRaiseWindow(dpy,t->IconView); - } -} + PagerWindow *t; + Window target_w; + target_w = body[0]; + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; + } + if (t != NULL) { + if (t->PagerView != None) + XRaiseWindow(dpy, t->PagerView); + XRaiseWindow(dpy, t->IconView); + } +} /*********************************************************************** * @@ -706,27 +662,25 @@ void list_raise(unsigned long *body) * list_lower - displays packet contents to stderr * ***********************************************************************/ -void list_lower(unsigned long *body) +void +list_lower(unsigned long *body) { - PagerWindow *t; - Window target_w; - - target_w = body[0]; - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t!= NULL) - { - if(t->PagerView != None) - XLowerWindow(dpy,t->PagerView); - if((t->desk - desk1>=0)&&(t->desk - desk1desk - desk1].CPagerWin); - XLowerWindow(dpy,t->IconView); - } -} + PagerWindow *t; + Window target_w; + target_w = body[0]; + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; + } + if (t != NULL) { + if (t->PagerView != None) + XLowerWindow(dpy, t->PagerView); + if ((t->desk - desk1 >= 0) && (t->desk - desk1 < ndesks)) + XLowerWindow(dpy, Desks[t->desk - desk1].CPagerWin); + XLowerWindow(dpy, t->IconView); + } +} /*********************************************************************** * @@ -734,9 +688,10 @@ void list_lower(unsigned long *body) * list_unknow - handles an unrecognized packet. * ***********************************************************************/ -void list_unknown(unsigned long *body) +void +list_unknown(unsigned long *body) { - /* fprintf(stderr,"Unknown packet type\n");*/ + /* fprintf(stderr,"Unknown packet type\n");*/ } /*********************************************************************** @@ -745,49 +700,44 @@ void list_unknown(unsigned long *body) * list_iconify - displays packet contents to stderr * ***********************************************************************/ -void list_iconify(unsigned long *body) +void +list_iconify(unsigned long *body) { - PagerWindow *t; - Window target_w; - - target_w = body[0]; - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t== NULL) - { - return; - } - else - { - t->t = (char *)body[2]; - t->frame = body[1]; - t->icon_x = body[3]; - t->icon_y = body[4]; - t->icon_width = body[5]; - t->icon_height = body[6]; - t->flags |= ICONIFIED; - t->x = t->icon_x; - t->y = t->icon_y; - if(t->flags & SUPPRESSICON) - { - t->x = -10000; - t->y = -10000; + PagerWindow *t; + Window target_w; + + target_w = body[0]; + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; } - t->width = t->icon_width; - t->height = t->icon_height; + if (t == NULL) { + return; + } else { + t->t = (char *)body[2]; + t->frame = body[1]; + t->icon_x = body[3]; + t->icon_y = body[4]; + t->icon_width = body[5]; + t->icon_height = body[6]; + t->flags |= ICONIFIED; + t->x = t->icon_x; + t->y = t->icon_y; + if (t->flags & SUPPRESSICON) { + t->x = -10000; + t->y = -10000; + } + t->width = t->icon_width; + t->height = t->icon_height; - /* if iconifying main pager window turn balloons on or off */ - if ( t->w == Scr.Pager_w ) - ShowBalloons = ShowIconBalloons; + /* if iconifying main pager window turn balloons on or off */ + if (t->w == Scr.Pager_w) + ShowBalloons = ShowIconBalloons; - MoveResizePagerView(t); - } + MoveResizePagerView(t); + } } - /*********************************************************************** * * Procedure: @@ -795,41 +745,37 @@ void list_iconify(unsigned long *body) * ***********************************************************************/ -void list_deiconify(unsigned long *body) +void +list_deiconify(unsigned long *body) { - PagerWindow *t; - Window target_w; - - target_w = body[0]; - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t== NULL) - { - return; - } - else - { - t->flags &= ~ICONIFIED; - t->x = t->frame_x; - t->y = t->frame_y; - t->width = t->frame_width; - t->height = t->frame_height; - - /* if deiconifying main pager window turn balloons on or off */ - if ( t->w == Scr.Pager_w ) - ShowBalloons = ShowPagerBalloons; - - MoveResizePagerView(t); - if(FocusWin == t) - Hilight(t,ON); - else - Hilight(t,OFF); - } -} + PagerWindow *t; + Window target_w; + target_w = body[0]; + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; + } + if (t == NULL) { + return; + } else { + t->flags &= ~ICONIFIED; + t->x = t->frame_x; + t->y = t->frame_y; + t->width = t->frame_width; + t->height = t->frame_height; + + /* if deiconifying main pager window turn balloons on or off */ + if (t->w == Scr.Pager_w) + ShowBalloons = ShowPagerBalloons; + + MoveResizePagerView(t); + if (FocusWin == t) + Hilight(t, ON); + else + Hilight(t, OFF); + } +} /*********************************************************************** * @@ -837,529 +783,430 @@ void list_deiconify(unsigned long *body) * list_icon_name - displays packet contents to stderr * ***********************************************************************/ -void list_icon_name(unsigned long *body) +void +list_icon_name(unsigned long *body) { - PagerWindow *t; - Window target_w; - - target_w = body[0]; - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t!= NULL) - { - if(t->icon_name != NULL) - free(t->icon_name); - CopyString(&t->icon_name,(char *)(&body[3])); - LabelWindow(t); - LabelIconWindow(t); - } -} + PagerWindow *t; + Window target_w; + target_w = body[0]; + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; + } + if (t != NULL) { + if (t->icon_name != NULL) + free(t->icon_name); + CopyString(&t->icon_name, (char *)(&body[3])); + LabelWindow(t); + LabelIconWindow(t); + } +} -void list_mini_icon(unsigned long *body) +void +list_mini_icon(unsigned long *body) { - PagerWindow *t; - Window target_w; - target_w = body[0]; - t = Start; - while (t && (t->w != target_w)) - t = t->next; - if (t) - { - t->mini_icon.width = body[3]; - t->mini_icon.height = body[4]; - t->mini_icon.depth = body[5]; - t->mini_icon.picture = body[6]; - t->mini_icon.mask = body[7]; - PictureWindow (t); - PictureIconWindow (t); - } + PagerWindow *t; + Window target_w; + target_w = body[0]; + t = Start; + while (t && (t->w != target_w)) + t = t->next; + if (t) { + t->mini_icon.width = body[3]; + t->mini_icon.height = body[4]; + t->mini_icon.depth = body[5]; + t->mini_icon.picture = body[6]; + t->mini_icon.mask = body[7]; + PictureWindow(t); + PictureIconWindow(t); + } } - /*********************************************************************** * * Procedure: * list_end - displays packet contents to stderr * ***********************************************************************/ -void list_end(void) +void +list_end(void) { - unsigned int nchildren,i; - Window root, parent, *children; - PagerWindow *ptr; - - if(!XQueryTree(dpy, Scr.Root, &root, &parent, &children, &nchildren)) - return; - - for(i=0; iframe == children[i])||(ptr->icon_w == children[i])|| - (ptr->icon_pixmap_w == children[i])) - { - if(ptr->PagerView != None) - XRaiseWindow(dpy,ptr->PagerView); - XRaiseWindow(dpy,ptr->IconView); - } - ptr = ptr->next; + unsigned int nchildren, i; + Window root, parent, *children; + PagerWindow *ptr; + + if (!XQueryTree(dpy, Scr.Root, &root, &parent, &children, &nchildren)) + return; + + for (i = 0; i < nchildren; i++) { + ptr = Start; + while (ptr != NULL) { + if ((ptr->frame == children[i]) || + (ptr->icon_w == children[i]) || + (ptr->icon_pixmap_w == children[i])) { + if (ptr->PagerView != None) + XRaiseWindow(dpy, ptr->PagerView); + XRaiseWindow(dpy, ptr->IconView); + } + ptr = ptr->next; + } } - } - - if(nchildren > 0) - XFree((char *)children); + if (nchildren > 0) + XFree((char *)children); } - - - /*************************************************************************** * * 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) { - fd_set in_fdset; - unsigned long header[HEADER_SIZE]; - static int miss_counter = 0; - unsigned long *body; - - if(XPending(dpy)) - { - XNextEvent(dpy,event); - return 1; - } - - FD_ZERO(&in_fdset); - FD_SET(x_fd,&in_fdset); - FD_SET(fd[1],&in_fdset); - - if (select(fd_width,SELECT_TYPE_ARG234 &in_fdset, 0, 0, NULL) > 0) - { - if(FD_ISSET(x_fd, &in_fdset)) - { - if(XPending(dpy)) - { - XNextEvent(dpy,event); - miss_counter = 0; - return 1; + fd_set in_fdset; + unsigned long header[HEADER_SIZE]; + static int miss_counter = 0; + unsigned long *body; + + if (XPending(dpy)) { + XNextEvent(dpy, event); + return 1; } - miss_counter++; - if(miss_counter > 100) - DeadPipe(0); - } - - if(FD_ISSET(fd[1], &in_fdset)) - { - if(ReadFvwmPacket(fd[1],header,&body) > 0) - { - process_message(header[1],body); - free(body); - } - } - } - return 0; -} + FD_ZERO(&in_fdset); + FD_SET(x_fd, &in_fdset); + FD_SET(fd[1], &in_fdset); + + if (select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL) > 0) { + if (FD_ISSET(x_fd, &in_fdset)) { + if (XPending(dpy)) { + XNextEvent(dpy, event); + miss_counter = 0; + return 1; + } + miss_counter++; + if (miss_counter > 100) + DeadPipe(0); + } + if (FD_ISSET(fd[1], &in_fdset)) { + if (ReadFvwmPacket(fd[1], header, &body) > 0) { + process_message(header[1], body); + free(body); + } + } + } + return 0; +} /***************************************************************************** * * This routine is responsible for reading and parsing the config file * ****************************************************************************/ -void ParseOptions(void) +void +ParseOptions(void) { - char *tline= NULL; - int Clength,n,desk; - - Scr.FvwmRoot = NULL; - Scr.Hilite = NULL; - Scr.VScale = 32; - - Scr.MyDisplayWidth = DisplayWidth(dpy, Scr.screen); - Scr.MyDisplayHeight = DisplayHeight(dpy, Scr.screen); - - Scr.VxMax = 3*Scr.MyDisplayWidth - Scr.MyDisplayWidth; - Scr.VyMax = 3*Scr.MyDisplayHeight - Scr.MyDisplayHeight; - if(Scr.VxMax <0) - Scr.VxMax = 0; - if(Scr.VyMax <0) - Scr.VyMax = 0; - Scr.Vx = 0; - Scr.Vy = 0; - - Clength = strlen(MyName); - - for (GetConfigLine(fd,&tline); tline != NULL; GetConfigLine(fd,&tline)) - { - int g_x, g_y, flags; - unsigned width,height; - char *resource; - char *resource_string; - char *arg1; - char *arg2; - char *tline2; - - resource_string = arg1 = arg2 = NULL; - tline2 = GetModuleResource(tline, &resource, MyName); - if (!resource) - continue; - tline2 = GetNextToken(tline2, &arg1); - if (!arg1) - { - arg1 = (char *)safemalloc(1); - arg1[0] = 0; - } - tline2 = GetNextToken(tline2, &arg2); - if (!arg2) - { - arg2 = (char *)safemalloc(1); - arg2[0] = 0; - } - - if (StrEquals(resource, "Geometry")) - { - flags = XParseGeometry(arg1,&g_x,&g_y,&width,&height); - if (flags & WidthValue) - { - window_w = width; - } - if (flags & HeightValue) - { - window_h = height; - } - if (flags & XValue) - { - window_x = g_x; - usposition = 1; - } - if (flags & YValue) - { - window_y = g_y; - usposition = 1; - } - if (flags & XNegative) - { - xneg = 1; - } - if (flags & YNegative) - { - window_y = g_y; - yneg = 1; - } - } - else if (StrEquals(resource, "IconGeometry")) - { - flags = XParseGeometry(arg1,&g_x,&g_y,&width,&height); - if (flags & WidthValue) - icon_w = width; - if (flags & HeightValue) - icon_h = height; - if (flags & XValue) - { - icon_x = g_x; - } - if (flags & YValue) - { - icon_y = g_y; - } - } - else if (StrEquals(resource, "Label")) - { - if (StrEquals(arg1, "*")) - { - desk = Scr.CurrentDesk; - } - else - { - desk = desk1; - sscanf(arg1,"%d",&desk); - } - if (fAlwaysCurrentDesk) - { - PagerStringList *item; - - item = FindDeskStrings(desk); - if (item->next != NULL) - { - /* replace label */ - if (item->next->label != NULL) - { - free(item->next->label); - item->next->label = NULL; - } - CopyString(&(item->next->label), arg2); + char *tline = NULL; + int Clength, n, desk; + + Scr.FvwmRoot = NULL; + Scr.Hilite = NULL; + Scr.VScale = 32; + + Scr.MyDisplayWidth = DisplayWidth(dpy, Scr.screen); + Scr.MyDisplayHeight = DisplayHeight(dpy, Scr.screen); + + Scr.VxMax = 3 * Scr.MyDisplayWidth - Scr.MyDisplayWidth; + Scr.VyMax = 3 * Scr.MyDisplayHeight - Scr.MyDisplayHeight; + if (Scr.VxMax < 0) + Scr.VxMax = 0; + if (Scr.VyMax < 0) + Scr.VyMax = 0; + Scr.Vx = 0; + Scr.Vy = 0; + + Clength = strlen(MyName); + + for (GetConfigLine(fd, &tline); tline != NULL; + GetConfigLine(fd, &tline)) { + int g_x, g_y, flags; + unsigned width, height; + char *resource; + char *resource_string; + char *arg1; + char *arg2; + char *tline2; + + resource_string = arg1 = arg2 = NULL; + tline2 = GetModuleResource(tline, &resource, MyName); + if (!resource) + continue; + tline2 = GetNextToken(tline2, &arg1); + if (!arg1) { + arg1 = (char *)xmalloc(1); + arg1[0] = 0; } - else - { - /* new Dcolor and desktop */ - item = NewPagerStringItem(item, desk); - CopyString(&(item->label), arg2); + tline2 = GetNextToken(tline2, &arg2); + if (!arg2) { + arg2 = (char *)xmalloc(1); + arg2[0] = 0; } - if (desk == Scr.CurrentDesk) - { - free(Desks[0].label); - CopyString(&Desks[0].label, arg2); - } - } - else if((desk >= desk1)&&(desk <=desk2)) - { - free(Desks[desk - desk1].label); - CopyString(&Desks[desk - desk1].label, arg2); - } - } - else if (StrEquals(resource, "Font")) - { - if (font_string) - free(font_string); - CopyString(&font_string,arg1); - if(strncasecmp(font_string,"none",4) == 0) - uselabel = 0; - } - else if (StrEquals(resource, "Fore")) - { - if(Scr.d_depth > 1) - { - if (PagerFore) - free(PagerFore); - CopyString(&PagerFore,arg1); - } - } - else if (StrEquals(resource, "Back")) - { - if(Scr.d_depth > 1) - { - if (PagerBack) - free(PagerBack); - CopyString(&PagerBack,arg1); - for (n=0;nnext != NULL) { + /* replace label */ + if (item->next->label != NULL) { + free(item->next->label); + item->next->label = NULL; + } + CopyString(&(item->next->label), arg2); + } else { + /* new Dcolor and desktop */ + item = NewPagerStringItem(item, desk); + CopyString(&(item->label), arg2); + } + if (desk == Scr.CurrentDesk) { + free(Desks[0].label); + CopyString(&Desks[0].label, arg2); + } + } else if ((desk >= desk1) && (desk <= desk2)) { + free(Desks[desk - desk1].label); + CopyString(&Desks[desk - desk1].label, arg2); + } + } else if (StrEquals(resource, "Font")) { + if (font_string) + free(font_string); + CopyString(&font_string, arg1); + if (strncasecmp(font_string, "none", 4) == 0) + uselabel = 0; + } else if (StrEquals(resource, "Fore")) { + if (Scr.d_depth > 1) { + if (PagerFore) + free(PagerFore); + CopyString(&PagerFore, arg1); + } + } else if (StrEquals(resource, "Back")) { + if (Scr.d_depth > 1) { + if (PagerBack) + free(PagerBack); + CopyString(&PagerBack, arg1); + for (n = 0; n < ndesks; n++) { + free(Desks[n].Dcolor); + CopyString(&Desks[n].Dcolor, PagerBack); #ifdef DEBUG - fprintf(stderr, - "[ParseOptions]: Back Desks[%d].Dcolor == %s\n", - n,Desks[n].Dcolor); + fprintf(stderr, + "[ParseOptions]: Back " + "Desks[%d].Dcolor == %s\n", + n, Desks[n].Dcolor); #endif + } + } + } else if (StrEquals(resource, "DeskColor")) { + if (StrEquals(arg1, "*")) { + desk = Scr.CurrentDesk; + } else { + desk = desk1; + sscanf(arg1, "%d", &desk); + } + if (fAlwaysCurrentDesk) { + PagerStringList *item; + + item = FindDeskStrings(desk); + if (item->next != NULL) { + /* replace Dcolor */ + if (item->next->Dcolor != NULL) { + free(item->next->Dcolor); + item->next->Dcolor = NULL; + } + CopyString(&(item->next->Dcolor), arg2); + } else { + /* new Dcolor and desktop */ + item = NewPagerStringItem(item, desk); + CopyString(&(item->Dcolor), arg2); + } + if (desk == Scr.CurrentDesk) { + free(Desks[0].Dcolor); + CopyString(&Desks[0].Dcolor, arg2); + } + } else if ((desk >= desk1) && (desk <= desk2)) { + free(Desks[desk - desk1].Dcolor); + CopyString(&Desks[desk - desk1].Dcolor, arg2); + } + } else if (StrEquals(resource, "Hilight")) { + if (Scr.d_depth > 1) { + if (HilightC) + free(HilightC); + CopyString(&HilightC, arg1); + } + } else if (StrEquals(resource, "SmallFont")) { + if (smallFont) + free(smallFont); + CopyString(&smallFont, arg1); + if (strncasecmp(smallFont, "none", 4) == 0) { + free(smallFont); + smallFont = NULL; + } + } else if (StrEquals(resource, "MiniIcons")) { + MiniIcons = 1; + } else if (StrEquals(resource, "StartIconic")) { + StartIconic = 1; + } else if (StrEquals(resource, "Rows")) { + sscanf(arg1, "%d", &Rows); + } else if (StrEquals(resource, "Columns")) { + sscanf(arg1, "%d", &Columns); + } else if (StrEquals(resource, "DeskTopScale")) { + sscanf(arg1, "%d", &Scr.VScale); + } else if (StrEquals(resource, "WindowColors")) { + if (Scr.d_depth > 1) { + if (WindowFore) + free(WindowFore); + if (WindowBack) + free(WindowBack); + if (WindowHiFore) + free(WindowHiFore); + if (WindowHiBack) + free(WindowHiBack); + CopyString(&WindowFore, arg1); + CopyString(&WindowBack, arg2); + tline2 = GetNextToken(tline2, &WindowHiFore); + GetNextToken(tline2, &WindowHiBack); + } } - } - } - else if (StrEquals(resource, "DeskColor")) - { - if (StrEquals(arg1, "*")) - { - desk = Scr.CurrentDesk; - } - else - { - desk = desk1; - sscanf(arg1,"%d",&desk); - } - if (fAlwaysCurrentDesk) - { - PagerStringList *item; - - item = FindDeskStrings(desk); - if (item->next != NULL) - { - /* replace Dcolor */ - if (item->next->Dcolor != NULL) - { - free(item->next->Dcolor); - item->next->Dcolor = NULL; - } - CopyString(&(item->next->Dcolor), arg2); - } - else - { - /* new Dcolor and desktop */ - item = NewPagerStringItem(item, desk); - CopyString(&(item->Dcolor), arg2); - } - if (desk == Scr.CurrentDesk) - { - free(Desks[0].Dcolor); - CopyString(&Desks[0].Dcolor, arg2); - } - } - else if((desk >= desk1)&&(desk <=desk2)) - { - free(Desks[desk - desk1].Dcolor); - CopyString(&Desks[desk - desk1].Dcolor, arg2); - } - } - else if (StrEquals(resource, "Hilight")) - { - if(Scr.d_depth > 1) - { - if (HilightC) - free(HilightC); - CopyString(&HilightC,arg1); - } - } - else if (StrEquals(resource, "SmallFont")) - { - if (smallFont) - free(smallFont); - CopyString(&smallFont,arg1); - if(strncasecmp(smallFont,"none",4) == 0) - { - free(smallFont); - smallFont = NULL; - } - } - else if (StrEquals(resource, "MiniIcons")) - { - MiniIcons = 1; - } - else if (StrEquals(resource, "StartIconic")) - { - StartIconic = 1; - } - else if (StrEquals(resource, "Rows")) - { - sscanf(arg1,"%d",&Rows); - } - else if (StrEquals(resource, "Columns")) - { - sscanf(arg1,"%d",&Columns); - } - else if (StrEquals(resource, "DeskTopScale")) - { - sscanf(arg1,"%d",&Scr.VScale); - } - else if (StrEquals(resource, "WindowColors")) - { - if (Scr.d_depth > 1) - { - if (WindowFore) - free(WindowFore); - if (WindowBack) - free(WindowBack); - if (WindowHiFore) - free(WindowHiFore); - if (WindowHiBack) - free(WindowHiBack); - CopyString(&WindowFore, arg1); - CopyString(&WindowBack, arg2); - tline2 = GetNextToken(tline2, &WindowHiFore); - GetNextToken(tline2, &WindowHiBack); - } - } + /* ... and get Balloon config options ... + -- ric@giccs.georgetown.edu */ + else if (StrEquals(resource, "Balloons")) { + if (BalloonTypeString) + free(BalloonTypeString); + CopyString(&BalloonTypeString, arg1); + + if (strncasecmp(BalloonTypeString, "Pager", 5) == 0) { + ShowPagerBalloons = 1; + ShowIconBalloons = 0; + } else if (strncasecmp(BalloonTypeString, "Icon", 4) == + 0) { + ShowPagerBalloons = 0; + ShowIconBalloons = 1; + } else { + ShowPagerBalloons = 1; + ShowIconBalloons = 1; + } + + /* turn this on initially so balloon window is created; + later this variable is changed to match + ShowPagerBalloons or ShowIconBalloons whenever we + receive iconify or deiconify packets */ + ShowBalloons = 1; + } else if (StrEquals(resource, "BalloonBack")) { + if (Scr.d_depth > 1) { + if (BalloonBack) + free(BalloonBack); + CopyString(&BalloonBack, arg1); + } + } else if (StrEquals(resource, "BalloonFore")) { + if (Scr.d_depth > 1) { + if (BalloonFore) + free(BalloonFore); + CopyString(&BalloonFore, arg1); + } + } else if (StrEquals(resource, "BalloonFont")) { + if (BalloonFont) + free(BalloonFont); + CopyString(&BalloonFont, arg1); + } else if (StrEquals(resource, "BalloonBorderColor")) { + if (BalloonBorderColor) + free(BalloonBorderColor); + CopyString(&BalloonBorderColor, arg1); + } else if (StrEquals(resource, "BalloonBorderWidth")) { + sscanf(arg1, "%d", &BalloonBorderWidth); + } else if (StrEquals(resource, "BalloonYOffset")) { + sscanf(arg1, "%d", &BalloonYOffset); + } - /* ... and get Balloon config options ... - -- ric@giccs.georgetown.edu */ - else if (StrEquals(resource, "Balloons")) - { - if (BalloonTypeString) - free(BalloonTypeString); - CopyString(&BalloonTypeString, arg1); - - if ( strncasecmp(BalloonTypeString, "Pager", 5) == 0 ) { - ShowPagerBalloons = 1; - ShowIconBalloons = 0; - } - else if ( strncasecmp(BalloonTypeString, "Icon", 4) == 0 ) { - ShowPagerBalloons = 0; - ShowIconBalloons = 1; - } - else { - ShowPagerBalloons = 1; - ShowIconBalloons = 1; - } - - /* turn this on initially so balloon window is created; later this - variable is changed to match ShowPagerBalloons or ShowIconBalloons - whenever we receive iconify or deiconify packets */ - ShowBalloons = 1; - } - - else if (StrEquals(resource, "BalloonBack")) - { - if (Scr.d_depth > 1) - { - if (BalloonBack) - free(BalloonBack); - CopyString(&BalloonBack, arg1); - } - } - - else if (StrEquals(resource, "BalloonFore")) - { - if (Scr.d_depth > 1) - { - if (BalloonFore) - free(BalloonFore); - CopyString(&BalloonFore, arg1); - } - } - - else if (StrEquals(resource, "BalloonFont")) - { - if (BalloonFont) - free(BalloonFont); - CopyString(&BalloonFont, arg1); - } - - else if (StrEquals(resource, "BalloonBorderColor")) - { - if (BalloonBorderColor) - free(BalloonBorderColor); - CopyString(&BalloonBorderColor, arg1); - } - - else if (StrEquals(resource, "BalloonBorderWidth")) - { - sscanf(arg1, "%d", &BalloonBorderWidth); - } - - else if (StrEquals(resource, "BalloonYOffset")) - { - sscanf(arg1, "%d", &BalloonYOffset); + free(resource); + free(arg1); + free(arg2); } - - free(resource); - free(arg1); - free(arg2); - } - return; + return; } /* Returns the item in the sring list that has item->next->desk == desk or * the last item (item->next == NULL) if no entry matches the desk number. */ -PagerStringList *FindDeskStrings(int desk) +PagerStringList * +FindDeskStrings(int desk) { - PagerStringList *item; - - item = &string_list; - while (item->next != NULL) - { - if (item->next->desk == desk) - break; - item = item->next; - } - return item; + PagerStringList *item; + + item = &string_list; + while (item->next != NULL) { + if (item->next->desk == desk) + break; + item = item->next; + } + return item; } -PagerStringList *NewPagerStringItem(PagerStringList *last, int desk) +PagerStringList * +NewPagerStringItem(PagerStringList *last, int desk) { - PagerStringList *newitem; + PagerStringList *newitem; - newitem = (PagerStringList *)safemalloc(sizeof(PagerStringList)); - last->next = newitem; - newitem->desk = desk; - newitem->next = NULL; - newitem->label = NULL; - newitem->Dcolor = NULL; + newitem = (PagerStringList *)xmalloc(sizeof(PagerStringList)); + last->next = newitem; + newitem->desk = desk; + newitem->next = NULL; + newitem->label = NULL; + newitem->Dcolor = NULL; - return newitem; + return newitem; } Index: fvwm/modules/FvwmPager/FvwmPager.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmPager/FvwmPager.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmPager/FvwmPager.h --- fvwm/modules/FvwmPager/FvwmPager.h +++ fvwm/modules/FvwmPager/FvwmPager.h @@ -1,101 +1,93 @@ -typedef struct ScreenInfo -{ - unsigned long screen; - int d_depth; /* copy of DefaultDepth(dpy, screen) */ - int MyDisplayWidth; /* my copy of DisplayWidth(dpy, screen) */ - int MyDisplayHeight; /* my copy of DisplayHeight(dpy, screen) */ - - char *FvwmRoot; /* the head of the fvwm window list */ - Window Root; /* the root window */ - - Window Pager_w; - - Font PagerFont; /* font struct for window labels in pager (optional)*/ - - GC NormalGC; /* normal GC for menus, pager, resize window */ - - char *Hilite; /* the fvwm window that is highlighted - * except for networking delays, this is the - * window which REALLY has the focus */ - unsigned VScale; /* Panner scale factor */ - 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 CurrentDesk; - Pixmap sticky_gray_pixmap; - Pixmap light_gray_pixmap; - Pixmap gray_pixmap; - +typedef struct ScreenInfo { + unsigned long screen; + int d_depth; /* copy of DefaultDepth(dpy, screen) */ + int MyDisplayWidth; /* my copy of DisplayWidth(dpy, screen) */ + int MyDisplayHeight; /* my copy of DisplayHeight(dpy, screen) */ + + char *FvwmRoot; /* the head of the fvwm window list */ + Window Root; /* the root window */ + + Window Pager_w; + + Font PagerFont; /* font struct for window labels in pager (optional)*/ + + GC NormalGC; /* normal GC for menus, pager, resize window */ + + char *Hilite; /* the fvwm window that is highlighted + * except for networking delays, this is the + * window which REALLY has the focus */ + unsigned VScale; /* Panner scale factor */ + 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 CurrentDesk; + Pixmap sticky_gray_pixmap; + Pixmap light_gray_pixmap; + Pixmap gray_pixmap; } ScreenInfo; -typedef struct pager_window -{ - char *t; - Window w; - Window frame; - int x; - int y; - int width; - int height; - int desk; - int frame_x; - int frame_y; - int frame_width; - int frame_height; - int title_height; - int border_width; - int icon_x; - int icon_y; - int icon_width; - int icon_height; - Pixel text; - Pixel back; - unsigned long flags; - Window icon_w; - Window icon_pixmap_w; - char *icon_name; - FvwmPicture mini_icon; - int pager_view_width; - int pager_view_height; - int icon_view_width; - int icon_view_height; - - Window PagerView; - Window IconView; - - struct pager_window *next; +typedef struct pager_window { + char *t; + Window w; + Window frame; + int x; + int y; + int width; + int height; + int desk; + int frame_x; + int frame_y; + int frame_width; + int frame_height; + int title_height; + int border_width; + int icon_x; + int icon_y; + int icon_width; + int icon_height; + Pixel text; + Pixel back; + unsigned long flags; + Window icon_w; + Window icon_pixmap_w; + char *icon_name; + FvwmPicture mini_icon; + int pager_view_width; + int pager_view_height; + int icon_view_width; + int icon_view_height; + + Window PagerView; + Window IconView; + + struct pager_window *next; } PagerWindow; - -typedef struct balloon_window -{ - Window w; /* ID of balloon window */ - PagerWindow *pw; /* pager window it's associated with */ - XFontStruct *font; - int height; /* height of balloon window based on font */ - int border; /* border width */ - int yoffset; /* pixels above (<0) or below (>0) pager win */ +typedef struct balloon_window { + Window w; /* ID of balloon window */ + PagerWindow *pw; /* pager window it's associated with */ + XFontStruct *font; + int height; /* height of balloon window based on font */ + int border; /* border width */ + int yoffset; /* pixels above (<0) or below (>0) pager win */ } BalloonWindow; - -typedef struct desk_info -{ - Window w; - Window title_w; - Window CPagerWin; - int x; - int y; - char *Dcolor; - char *label; +typedef struct desk_info { + Window w; + Window title_w; + Window CPagerWin; + int x; + int y; + char *Dcolor; + char *label; } DeskInfo; -typedef struct pager_string_list -{ - struct pager_string_list *next; - int desk; - char *Dcolor; - char *label; +typedef struct pager_string_list { + struct pager_string_list *next; + int desk; + char *Dcolor; + char *label; } PagerStringList; #define ON 1 @@ -106,12 +98,11 @@ typedef struct pager_string_list * Subroutine Prototypes * *************************************************************************/ -char *GetNextToken(char *indata,char **token); +char *GetNextToken(char *indata, char **token); void Loop(int *fd); -void SendInfo(int *fd,char *message,unsigned long window); -char *safemalloc(int length); +void SendInfo(int *fd, char *message, unsigned long window); void DeadPipe(int nonsense); -void process_message(unsigned long type,unsigned long *body); +void process_message(unsigned long type, unsigned long *body); void ParseOptions(void); void list_add(unsigned long *body); @@ -142,13 +133,13 @@ void DispatchEvent(XEvent *Event); void ReConfigure(void); void ReConfigureAll(void); void MovePage(void); -void DrawGrid(int i,int erase); +void DrawGrid(int i, int erase); void DrawIconGrid(int erase); void SwitchToDesk(int Desk); void SwitchToDeskAndPage(int Desk, XEvent *Event); void AddNewWindow(PagerWindow *prev); void MoveResizePagerView(PagerWindow *t); -void ChangeDeskForWindow(PagerWindow *t,long newdesk); +void ChangeDeskForWindow(PagerWindow *t, long newdesk); void MoveStickyWindow(void); void Hilight(PagerWindow *, int); void Scroll(int window_w, int window_h, int x, int y, int Desk); @@ -159,13 +150,9 @@ void PictureWindow(PagerWindow *t); void PictureIconWindow(PagerWindow *t); void ReConfigureIcons(void); void IconSwitchPage(XEvent *Event); -void IconMoveWindow(XEvent *Event,PagerWindow *t); +void IconMoveWindow(XEvent *Event, PagerWindow *t); void HandleExpose(XEvent *Event); void MoveStickyWindows(void); void MapBalloonWindow(XEvent *); void UnmapBalloonWindow(void); void DrawInBalloonWindow(void); - - - - Index: fvwm/modules/FvwmPager/x_pager.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmPager/x_pager.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmPager/x_pager.c --- fvwm/modules/FvwmPager/x_pager.c +++ fvwm/modules/FvwmPager/x_pager.c @@ -8,21 +8,19 @@ * ***********************************************************************/ -#include "config.h" - -#include -#include -#include - +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include -#include "../../libs/fvwmlib.h" #include "../../fvwm/fvwm.h" +#include "../../libs/fvwmlib.h" #include "FvwmPager.h" +#include "config.h" extern ScreenInfo Scr; extern Display *dpy; @@ -31,7 +29,8 @@ Pixel back_pix, fore_pix, hi_pix; Pixel focus_pix; Pixel focus_fore_pix; extern Pixel win_back_pix, win_fore_pix, win_hi_back_pix, win_hi_fore_pix; -extern int window_w, window_h,window_x,window_y,usposition,uselabel,xneg,yneg; +extern int window_w, window_h, window_x, window_y, usposition, uselabel, xneg, + yneg; extern int StartIconic; extern int MiniIcons; extern int ShowBalloons, ShowPagerBalloons, ShowIconBalloons; @@ -39,7 +38,7 @@ extern int ShowBalloons, ShowPagerBalloons, ShowIconBalloons; extern int icon_w, icon_h, icon_x, icon_y; XFontStruct *font, *windowFont; -GC NormalGC,DashedGC,HiliteGC,rvGC; +GC NormalGC, DashedGC, HiliteGC, rvGC; GC StdGC; GC MiniIconGC; GC BalloonGC; @@ -51,7 +50,7 @@ static Atom wm_del_win; extern char *MyName; extern int desk1, desk2, ndesks; -extern int Rows,Columns; +extern int Rows, Columns; extern int fd[2]; int desk_w = 0; @@ -62,7 +61,6 @@ DeskInfo *Desks; int Wait = 0; XErrorHandler FvwmErrorHandler(Display *, XErrorEvent *); - /* assorted gray bitmaps for decorative borders */ #define g_width 2 #define g_height 2 @@ -76,9 +74,8 @@ static char l_g_bits[] = {0x08, 0x02}; #define s_g_height 4 static char s_g_bits[] = {0x01, 0x02, 0x04, 0x08}; - -Window icon_win; /* icon window */ -BalloonWindow balloon; /* balloon window */ +Window icon_win; /* icon window */ +BalloonWindow balloon; /* balloon window */ /*********************************************************************** * @@ -90,437 +87,395 @@ BalloonWindow balloon; /* balloon window */ * ***********************************************************************/ char *pager_name = "Fvwm Pager"; -XSizeHints sizehints = -{ - (PMinSize | PResizeInc | PBaseSize | PWinGravity), - 0, 0, 100, 100, /* x, y, width and height */ - 1, 1, /* Min width and height */ - 0, 0, /* Max width and height */ - 1, 1, /* Width and height increments */ - {0, 0}, {0, 0}, /* Aspect ratio - not used */ - 1, 1, /* base size */ - (NorthWestGravity) /* gravity */ +XSizeHints sizehints = { + (PMinSize | PResizeInc | PBaseSize | PWinGravity), 0, 0, 100, + 100, /* x, y, width and height */ + 1, 1, /* Min width and height */ + 0, 0, /* Max width and height */ + 1, 1, /* Width and height increments */ + {0, 0}, {0, 0}, /* Aspect ratio - not used */ + 1, 1, /* base size */ + (NorthWestGravity) /* gravity */ }; -void initialize_pager(void) +void +initialize_pager(void) { - XWMHints wmhints; - XClassHint class1; - - XTextProperty name; - unsigned long valuemask; - XSetWindowAttributes attributes; - extern char *PagerFore, *PagerBack, *HilightC; - extern char *WindowBack, *WindowFore, *WindowHiBack, *WindowHiFore; - extern char *BalloonFore, *BalloonBack, *BalloonFont; - extern char *BalloonBorderColor; - extern int BalloonBorderWidth, BalloonYOffset; - extern char *font_string, *smallFont; - int n,m,w,h,i,x,y; - XGCValues gcv; - unsigned long gcm; + XWMHints wmhints; + XClassHint class1; + + XTextProperty name; + unsigned long valuemask; + XSetWindowAttributes attributes; + extern char *PagerFore, *PagerBack, *HilightC; + extern char *WindowBack, *WindowFore, *WindowHiBack, *WindowHiFore; + extern char *BalloonFore, *BalloonBack, *BalloonFont; + extern char *BalloonBorderColor; + extern int BalloonBorderWidth, BalloonYOffset; + extern char *font_string, *smallFont; + int n, m, w, h, i, x, y; + XGCValues gcv; + unsigned long gcm; #if 1 - /* I don't think that this is necessary - just let pager die */ - /* domivogt (07-mar-1999): But it is! A window being moved in the pager - * might die at any moment causing the Xlib calls to generate BadMatch - * errors. Without an error handler the pager will die! */ - XSetErrorHandler((XErrorHandler)FvwmErrorHandler); + /* I don't think that this is necessary - just let pager die */ + /* domivogt (07-mar-1999): But it is! A window being moved in the pager + * might die at any moment causing the Xlib calls to generate BadMatch + * errors. Without an error handler the pager will die! */ + XSetErrorHandler((XErrorHandler)FvwmErrorHandler); #endif /* 1 */ - wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); - /* load the font */ - if (!uselabel || ((font = XLoadQueryFont(dpy, font_string)) == NULL)) - { - if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) - { - fprintf(stderr,"%s: No fonts available\n",MyName); - exit(1); + /* load the font */ + if (!uselabel || ((font = XLoadQueryFont(dpy, font_string)) == NULL)) { + if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) { + fprintf(stderr, "%s: No fonts available\n", MyName); + exit(1); + } } - }; - if(uselabel) - label_h = font->ascent + font->descent+2; - else - label_h = 0; - - - if(smallFont!= NULL) - { - windowFont= XLoadQueryFont(dpy, smallFont); - } - else - windowFont= NULL; - - /* Load the colors */ - fore_pix = GetColor(PagerFore); - back_pix = GetColor(PagerBack); - hi_pix = GetColor(HilightC); - - if (WindowBack && WindowFore && WindowHiBack && WindowHiFore) - { - win_back_pix = GetColor (WindowBack); - win_fore_pix = GetColor (WindowFore); - win_hi_back_pix = GetColor (WindowHiBack); - win_hi_fore_pix = GetColor (WindowHiFore); - } - /* Load pixmaps for mono use */ - if(Scr.d_depth<2) - { - Scr.gray_pixmap = - XCreatePixmapFromBitmapData(dpy,Scr.Root,g_bits, g_width,g_height, - fore_pix,back_pix,Scr.d_depth); - Scr.light_gray_pixmap = - XCreatePixmapFromBitmapData(dpy,Scr.Root,l_g_bits,l_g_width,l_g_height, - fore_pix,back_pix,Scr.d_depth); - Scr.sticky_gray_pixmap = - XCreatePixmapFromBitmapData(dpy,Scr.Root,s_g_bits,s_g_width,s_g_height, - fore_pix,back_pix,Scr.d_depth); - } - - - n = Scr.VxMax/Scr.MyDisplayWidth; - m = Scr.VyMax/Scr.MyDisplayHeight; - - /* Size the window */ - if(Rows < 0) - { - if(Columns < 0) - { - Columns = ndesks; - Rows = 1; + if (uselabel) + label_h = font->ascent + font->descent + 2; + else + label_h = 0; + + if (smallFont != NULL) { + windowFont = XLoadQueryFont(dpy, smallFont); + } else + windowFont = NULL; + + /* Load the colors */ + fore_pix = GetColor(PagerFore); + back_pix = GetColor(PagerBack); + hi_pix = GetColor(HilightC); + + if (WindowBack && WindowFore && WindowHiBack && WindowHiFore) { + win_back_pix = GetColor(WindowBack); + win_fore_pix = GetColor(WindowFore); + win_hi_back_pix = GetColor(WindowHiBack); + win_hi_fore_pix = GetColor(WindowHiFore); } - else - { - Rows = ndesks/Columns; - if(Rows*Columns < ndesks) - Rows++; + /* Load pixmaps for mono use */ + if (Scr.d_depth < 2) { + Scr.gray_pixmap = XCreatePixmapFromBitmapData(dpy, Scr.Root, + g_bits, g_width, g_height, fore_pix, back_pix, Scr.d_depth); + Scr.light_gray_pixmap = + XCreatePixmapFromBitmapData(dpy, Scr.Root, l_g_bits, + l_g_width, l_g_height, fore_pix, back_pix, Scr.d_depth); + Scr.sticky_gray_pixmap = + XCreatePixmapFromBitmapData(dpy, Scr.Root, s_g_bits, + s_g_width, s_g_height, fore_pix, back_pix, Scr.d_depth); } - } - if(Columns < 0) - { - if (Rows == 0) - Rows = 1; - Columns = ndesks/Rows; - if(Rows*Columns < ndesks) - Columns++; - } - - if(Rows*Columns < ndesks) - { - if (Columns == 0) - Columns = 1; - Rows = ndesks/Columns; - if (Rows*Columns < ndesks) - Rows++; - } - if(window_w > 0) - { - window_w = ((window_w - n)/(n+1))*(n+1)+n; - Scr.VScale = Columns*(Scr.VxMax + Scr.MyDisplayWidth)/ - (window_w-Columns+1-Columns*n); - } - if(window_h > 0) - { - window_h = ((window_h - m)/(m+1))*(m+1)+m; - Scr.VScale = Rows*(Scr.VyMax + Scr.MyDisplayHeight)/ - (window_h+2-Rows*(label_h -m-1)); - } - if(window_w <= 0) - window_w = Columns*((Scr.VxMax + Scr.MyDisplayWidth)/Scr.VScale + n) + - Columns-1; - if(window_h <= 0) - { - window_h = Rows*((Scr.VyMax + Scr.MyDisplayHeight)/Scr.VScale - + m + label_h + 1)-2; - } - - if(xneg) - { - sizehints.win_gravity = NorthEastGravity; - window_x = Scr.MyDisplayWidth - window_w + window_x -2; - } - - if(yneg) - { - window_y = Scr.MyDisplayHeight - window_h + window_y -2; - if(sizehints.win_gravity == NorthEastGravity) - sizehints.win_gravity = SouthEastGravity; - else - sizehints.win_gravity = SouthWestGravity; - } - - if(usposition) - sizehints.flags |= USPosition; - - valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); - attributes.background_pixel = back_pix; - attributes.border_pixel = fore_pix; - attributes.event_mask = (StructureNotifyMask); - sizehints.width = window_w; - sizehints.height = window_h; - sizehints.x = window_x; - sizehints.y = window_y; - sizehints.width_inc = Columns*(n+1); - sizehints.height_inc = Rows*(m+1); - sizehints.base_width = Columns * n + Columns - 1; - sizehints.base_height = Rows*(m + label_h+1) -2; - sizehints.min_width = Columns * n + Columns - 1; - sizehints.min_height = Rows*(m + label_h+1) -2; - - Scr.Pager_w = XCreateWindow (dpy, Scr.Root, window_x, window_y, window_w, - window_h, (unsigned int) 1, - CopyFromParent, InputOutput, - (Visual *) CopyFromParent, - valuemask, &attributes); - XSetWMProtocols(dpy,Scr.Pager_w,&wm_del_win,1); - XSetWMNormalHints(dpy,Scr.Pager_w,&sizehints); - - if((desk1==desk2)&&(Desks[0].label != NULL)) - XStringListToTextProperty(&Desks[0].label,1,&name); - else - XStringListToTextProperty(&pager_name,1,&name); - - attributes.event_mask = (StructureNotifyMask| ExposureMask); - if(icon_w < 1) - icon_w = (window_w - Columns+1)/Columns; - if(icon_h < 1) - icon_h = (window_h - Rows* label_h - Rows + 1)/Rows; - - icon_w = (icon_w / (n+1)) *(n+1)+n; - icon_h = (icon_h / (m+1)) *(m+1)+m; - icon_win = XCreateWindow (dpy, Scr.Root, window_x, window_y, - icon_w,icon_h, - (unsigned int) 1, - CopyFromParent, InputOutput, - (Visual *) CopyFromParent, - valuemask, &attributes); - XGrabButton(dpy, 1, AnyModifier, icon_win, - True, ButtonPressMask | ButtonReleaseMask|ButtonMotionMask, - GrabModeAsync, GrabModeAsync, None, - None); - XGrabButton(dpy, 2, AnyModifier, icon_win, - True, ButtonPressMask | ButtonReleaseMask|ButtonMotionMask, - GrabModeAsync, GrabModeAsync, None, - None); - XGrabButton(dpy, 3, AnyModifier, icon_win, - True, ButtonPressMask | ButtonReleaseMask|ButtonMotionMask, - GrabModeAsync, GrabModeAsync, None, - None); - if(!StartIconic) - wmhints.initial_state = NormalState; - else - wmhints.initial_state = IconicState; - wmhints.flags = 0; - if(icon_x > -10000) - { - if(icon_x < 0) - icon_x = Scr.MyDisplayWidth + icon_x - icon_w; - if(icon_y > -10000) - { - if(icon_y < 0) - icon_y = Scr.MyDisplayHeight + icon_y - icon_h; + + n = Scr.VxMax / Scr.MyDisplayWidth; + m = Scr.VyMax / Scr.MyDisplayHeight; + + /* Size the window */ + if (Rows < 0) { + if (Columns < 0) { + Columns = ndesks; + Rows = 1; + } else { + Rows = ndesks / Columns; + if (Rows * Columns < ndesks) + Rows++; + } + } + if (Columns < 0) { + if (Rows == 0) + Rows = 1; + Columns = ndesks / Rows; + if (Rows * Columns < ndesks) + Columns++; + } + + if (Rows * Columns < ndesks) { + if (Columns == 0) + Columns = 1; + Rows = ndesks / Columns; + if (Rows * Columns < ndesks) + Rows++; + } + if (window_w > 0) { + window_w = ((window_w - n) / (n + 1)) * (n + 1) + n; + Scr.VScale = Columns * (Scr.VxMax + Scr.MyDisplayWidth) / + (window_w - Columns + 1 - Columns * n); + } + if (window_h > 0) { + window_h = ((window_h - m) / (m + 1)) * (m + 1) + m; + Scr.VScale = Rows * (Scr.VyMax + Scr.MyDisplayHeight) / + (window_h + 2 - Rows * (label_h - m - 1)); + } + if (window_w <= 0) + window_w = + Columns * + ((Scr.VxMax + Scr.MyDisplayWidth) / Scr.VScale + n) + + Columns - 1; + if (window_h <= 0) { + window_h = + Rows * ((Scr.VyMax + Scr.MyDisplayHeight) / Scr.VScale + m + + label_h + 1) - + 2; + } + + if (xneg) { + sizehints.win_gravity = NorthEastGravity; + window_x = Scr.MyDisplayWidth - window_w + window_x - 2; + } + + if (yneg) { + window_y = Scr.MyDisplayHeight - window_h + window_y - 2; + if (sizehints.win_gravity == NorthEastGravity) + sizehints.win_gravity = SouthEastGravity; + else + sizehints.win_gravity = SouthWestGravity; } - else - icon_y = 0; - wmhints.icon_x = icon_x; - wmhints.icon_y = icon_y; - wmhints.flags = IconPositionHint; - } - wmhints.icon_window = icon_win; - wmhints.input = False; - - wmhints.flags |= InputHint | StateHint | IconWindowHint; - - class1.res_name = MyName; - class1.res_class = "FvwmModule"; - - XSetWMProperties(dpy,Scr.Pager_w,&name,&name,NULL,0, - &sizehints,&wmhints,&class1); - XFree((char *)name.value); - - for(i=0;ifid; - NormalGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - MiniIconGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = hi_pix; - if(Scr.d_depth < 2) - { - gcv.foreground = fore_pix; - gcv.background = back_pix; - } - HiliteGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - if((Scr.d_depth < 2)||(fore_pix == hi_pix)) - gcv.foreground = back_pix; - else - gcv.foreground = fore_pix; - rvGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - if(windowFont != NULL) - { - /* Create GC's for doing window labels */ - gcv.foreground = focus_fore_pix; - gcv.background = focus_pix; - gcv.font = windowFont->fid; - StdGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - } - - gcm = gcm | GCLineStyle; - gcv.foreground = fore_pix; - gcv.background = back_pix; - gcv.line_style = LineOnOffDash; - DashedGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - - /* create balloon window - -- ric@giccs.georgetown.edu */ - if ( ShowBalloons ) { - - valuemask = CWOverrideRedirect | CWEventMask | CWBackPixel | CWBorderPixel; - - /* tell WM to ignore this window */ - attributes.override_redirect = True; - - attributes.event_mask = ExposureMask; - attributes.border_pixel = GetColor(BalloonBorderColor); - - /* if given in config set this now, otherwise it'll be set for each - pager window when drawn later */ - attributes.background_pixel = - (BalloonBack == NULL) ? 0 : GetColor(BalloonBack); - - /* get font for balloon */ - if ( (balloon.font = XLoadQueryFont(dpy, BalloonFont)) == NULL ) { - if ( (balloon.font = XLoadQueryFont(dpy, "fixed")) == NULL ) { - fprintf(stderr,"%s: No fonts available.\n", MyName); - exit(1); - } - fprintf(stderr, "%s: Can't find font '%s', using fixed.\n", - MyName, BalloonFont); - } - - balloon.height = balloon.font->ascent + balloon.font->descent + 1; - - /* this may have been set in config */ - balloon.border = BalloonBorderWidth; - - - /* we don't allow yoffset of 0 because it allows direct transit - from pager window to balloon window, setting up a - LeaveNotify/EnterNotify event loop */ - if ( BalloonYOffset ) - balloon.yoffset = BalloonYOffset; - else { - fprintf(stderr, - "%s: Warning: you're not allowed BalloonYOffset 0; defaulting to +2\n", - MyName); - balloon.yoffset = 2; - } - - /* now create the window */ - balloon.w = XCreateWindow(dpy, Scr.Root, - 0, 0, /* coords set later */ - 1, /* width set later */ - balloon.height, - balloon.border, - CopyFromParent, - InputOutput, - CopyFromParent, - valuemask, - &attributes); - - /* set font */ - gcv.font = balloon.font->fid; - - /* if fore given in config set now, otherwise it'll be set later */ - gcv.foreground = (BalloonFore == NULL) ? 0 : GetColor(BalloonFore); - - BalloonGC = XCreateGC(dpy, balloon.w, GCFont | GCForeground, &gcv); - - /* Make sure we don't get balloons initially with the Icon option. */ - ShowBalloons = ShowPagerBalloons; - } /* ShowBalloons */ -} + if (usposition) + sizehints.flags |= USPosition; + + valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); + attributes.background_pixel = back_pix; + attributes.border_pixel = fore_pix; + attributes.event_mask = (StructureNotifyMask); + sizehints.width = window_w; + sizehints.height = window_h; + sizehints.x = window_x; + sizehints.y = window_y; + sizehints.width_inc = Columns * (n + 1); + sizehints.height_inc = Rows * (m + 1); + sizehints.base_width = Columns * n + Columns - 1; + sizehints.base_height = Rows * (m + label_h + 1) - 2; + sizehints.min_width = Columns * n + Columns - 1; + sizehints.min_height = Rows * (m + label_h + 1) - 2; + + Scr.Pager_w = XCreateWindow(dpy, Scr.Root, window_x, window_y, window_w, + window_h, (unsigned int)1, CopyFromParent, InputOutput, + (Visual *)CopyFromParent, valuemask, &attributes); + XSetWMProtocols(dpy, Scr.Pager_w, &wm_del_win, 1); + XSetWMNormalHints(dpy, Scr.Pager_w, &sizehints); + + if ((desk1 == desk2) && (Desks[0].label != NULL)) + XStringListToTextProperty(&Desks[0].label, 1, &name); + else + XStringListToTextProperty(&pager_name, 1, &name); + + attributes.event_mask = (StructureNotifyMask | ExposureMask); + if (icon_w < 1) + icon_w = (window_w - Columns + 1) / Columns; + if (icon_h < 1) + icon_h = (window_h - Rows * label_h - Rows + 1) / Rows; + + icon_w = (icon_w / (n + 1)) * (n + 1) + n; + icon_h = (icon_h / (m + 1)) * (m + 1) + m; + icon_win = XCreateWindow(dpy, Scr.Root, window_x, window_y, icon_w, + icon_h, (unsigned int)1, CopyFromParent, InputOutput, + (Visual *)CopyFromParent, valuemask, &attributes); + XGrabButton(dpy, 1, AnyModifier, icon_win, True, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, + GrabModeAsync, GrabModeAsync, None, None); + XGrabButton(dpy, 2, AnyModifier, icon_win, True, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, + GrabModeAsync, GrabModeAsync, None, None); + XGrabButton(dpy, 3, AnyModifier, icon_win, True, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, + GrabModeAsync, GrabModeAsync, None, None); + if (!StartIconic) + wmhints.initial_state = NormalState; + else + wmhints.initial_state = IconicState; + wmhints.flags = 0; + if (icon_x > -10000) { + if (icon_x < 0) + icon_x = Scr.MyDisplayWidth + icon_x - icon_w; + if (icon_y > -10000) { + if (icon_y < 0) + icon_y = Scr.MyDisplayHeight + icon_y - icon_h; + } else + icon_y = 0; + wmhints.icon_x = icon_x; + wmhints.icon_y = icon_y; + wmhints.flags = IconPositionHint; + } + wmhints.icon_window = icon_win; + wmhints.input = False; + + wmhints.flags |= InputHint | StateHint | IconWindowHint; + + class1.res_name = MyName; + class1.res_class = "FvwmModule"; + + XSetWMProperties(dpy, Scr.Pager_w, &name, &name, NULL, 0, &sizehints, + &wmhints, &class1); + XFree((char *)name.value); + + for (i = 0; i < ndesks; i++) { + w = window_w / ndesks; + h = window_h; + x = w * i; + y = 0; + + valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); + attributes.background_pixel = GetColor(Desks[i].Dcolor); + attributes.border_pixel = fore_pix; + attributes.event_mask = (ExposureMask | ButtonReleaseMask); + Desks[i].title_w = XCreateWindow(dpy, Scr.Pager_w, x, y, w, h, + 1, CopyFromParent, InputOutput, CopyFromParent, valuemask, + &attributes); + attributes.event_mask = (ExposureMask | ButtonReleaseMask | + ButtonPressMask | ButtonMotionMask); + desk_h = window_h - label_h; + Desks[i].w = XCreateWindow(dpy, Desks[i].title_w, x, y, w, + desk_h, 1, CopyFromParent, InputOutput, CopyFromParent, + valuemask, &attributes); + + attributes.event_mask = 0; + attributes.background_pixel = hi_pix; + + w = (window_w - n) / (n + 1); + h = (window_h - label_h - m) / (m + 1); + Desks[i].CPagerWin = XCreateWindow(dpy, Desks[i].w, -1000, + -1000, w, h, 0, CopyFromParent, InputOutput, CopyFromParent, + valuemask, &attributes); + XMapRaised(dpy, Desks[i].CPagerWin); + XMapRaised(dpy, Desks[i].w); + XMapRaised(dpy, Desks[i].title_w); + } + XMapRaised(dpy, Scr.Pager_w); + + gcm = GCForeground | GCBackground | GCFont; + gcv.foreground = fore_pix; + gcv.background = back_pix; + + gcv.font = font->fid; + NormalGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + MiniIconGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = hi_pix; + if (Scr.d_depth < 2) { + gcv.foreground = fore_pix; + gcv.background = back_pix; + } + HiliteGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + if ((Scr.d_depth < 2) || (fore_pix == hi_pix)) + gcv.foreground = back_pix; + else + gcv.foreground = fore_pix; + rvGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + if (windowFont != NULL) { + /* Create GC's for doing window labels */ + gcv.foreground = focus_fore_pix; + gcv.background = focus_pix; + gcv.font = windowFont->fid; + StdGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + } + + gcm = gcm | GCLineStyle; + gcv.foreground = fore_pix; + gcv.background = back_pix; + gcv.line_style = LineOnOffDash; + DashedGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + /* create balloon window + -- ric@giccs.georgetown.edu */ + if (ShowBalloons) { + valuemask = CWOverrideRedirect | CWEventMask | CWBackPixel | + CWBorderPixel; + + /* tell WM to ignore this window */ + attributes.override_redirect = True; + + attributes.event_mask = ExposureMask; + attributes.border_pixel = GetColor(BalloonBorderColor); + + /* if given in config set this now, otherwise it'll be set for + each pager window when drawn later */ + attributes.background_pixel = + (BalloonBack == NULL) ? 0 : GetColor(BalloonBack); + + /* get font for balloon */ + if ((balloon.font = XLoadQueryFont(dpy, BalloonFont)) == NULL) { + if ((balloon.font = XLoadQueryFont(dpy, "fixed")) == + NULL) { + fprintf(stderr, "%s: No fonts available.\n", + MyName); + exit(1); + } + fprintf(stderr, + "%s: Can't find font '%s', using fixed.\n", MyName, + BalloonFont); + } + + balloon.height = + balloon.font->ascent + balloon.font->descent + 1; + + /* this may have been set in config */ + balloon.border = BalloonBorderWidth; + + /* we don't allow yoffset of 0 because it allows direct transit + from pager window to balloon window, setting up a + LeaveNotify/EnterNotify event loop */ + if (BalloonYOffset) + balloon.yoffset = BalloonYOffset; + else { + fprintf(stderr, + "%s: Warning: you're not allowed BalloonYOffset 0; " + "defaulting to +2\n", + MyName); + balloon.yoffset = 2; + } + /* now create the window */ + balloon.w = + XCreateWindow(dpy, Scr.Root, 0, 0, /* coords set later */ + 1, /* width set later */ + balloon.height, balloon.border, CopyFromParent, + InputOutput, CopyFromParent, valuemask, &attributes); + + /* set font */ + gcv.font = balloon.font->fid; + + /* if fore given in config set now, otherwise it'll be set later + */ + gcv.foreground = + (BalloonFore == NULL) ? 0 : GetColor(BalloonFore); + + BalloonGC = + XCreateGC(dpy, balloon.w, GCFont | GCForeground, &gcv); + + /* Make sure we don't get balloons initially with the Icon + * option. */ + ShowBalloons = ShowPagerBalloons; + } /* ShowBalloons */ +} /**************************************************************************** * * Loads a single color * ****************************************************************************/ -Pixel GetColor(char *name) +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(dpy,Scr.Root,&attributes); - color.pixel = 0; - if (!XParseColor (dpy, attributes.colormap, name, &color)) - { - nocolor("parse",name); - } - else if(!XAllocColor (dpy, attributes.colormap, &color)) - { - nocolor("alloc",name); - } - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(dpy, Scr.Root, &attributes); + color.pixel = 0; + if (!XParseColor(dpy, attributes.colormap, name, &color)) { + nocolor("parse", name); + } else if (!XAllocColor(dpy, attributes.colormap, &color)) { + nocolor("alloc", name); + } + return color.pixel; } - -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"%s: can't %s %s\n", MyName, a,b); + fprintf(stderr, "%s: can't %s %s\n", MyName, a, b); } /**************************************************************************** @@ -528,335 +483,318 @@ void nocolor(char *a, char *b) * Decide what to do about received X events * ****************************************************************************/ -void DispatchEvent(XEvent *Event) +void +DispatchEvent(XEvent *Event) { - int i,x,y; - Window JunkRoot, JunkChild; - int JunkX, JunkY; - unsigned JunkMask; - - switch(Event->xany.type) - { - case EnterNotify: - if ( ShowBalloons ) - MapBalloonWindow(Event); - break; - case LeaveNotify: - if ( ShowBalloons ) - UnmapBalloonWindow(); - break; - case ConfigureNotify: - ReConfigure(); - break; - case Expose: - HandleExpose(Event); - break; - case ButtonRelease: - if((Event->xbutton.button == 1)|| - (Event->xbutton.button == 2)) - { - for(i=0;ixany.window == Desks[i].w) - SwitchToDeskAndPage(i,Event); - if(Event->xany.window == Desks[i].title_w) - SwitchToDesk(i); - } - if(Event->xany.window == icon_win) - { - IconSwitchPage(Event); - } - } - else if (Event->xbutton.button == 3) - { - for(i=0;ixany.window == Desks[i].w) - { - XQueryPointer(dpy, Desks[i].w, &JunkRoot, &JunkChild, - &JunkX, &JunkY,&x, &y, &JunkMask); - Scroll(desk_w, desk_h, x, y, i); + int i, x, y; + Window JunkRoot, JunkChild; + int JunkX, JunkY; + unsigned JunkMask; + + switch (Event->xany.type) { + case EnterNotify: + if (ShowBalloons) + MapBalloonWindow(Event); + break; + case LeaveNotify: + if (ShowBalloons) + UnmapBalloonWindow(); + break; + case ConfigureNotify: + ReConfigure(); + break; + case Expose: + HandleExpose(Event); + break; + case ButtonRelease: + if ((Event->xbutton.button == 1) || + (Event->xbutton.button == 2)) { + for (i = 0; i < ndesks; i++) { + if (Event->xany.window == Desks[i].w) + SwitchToDeskAndPage(i, Event); + if (Event->xany.window == Desks[i].title_w) + SwitchToDesk(i); + } + if (Event->xany.window == icon_win) { + IconSwitchPage(Event); + } + } else if (Event->xbutton.button == 3) { + for (i = 0; i < ndesks; i++) { + if (Event->xany.window == Desks[i].w) { + XQueryPointer(dpy, Desks[i].w, + &JunkRoot, &JunkChild, &JunkX, + &JunkY, &x, &y, &JunkMask); + Scroll(desk_w, desk_h, x, y, i); + } + } + if (Event->xany.window == icon_win) { + XQueryPointer(dpy, icon_win, &JunkRoot, + &JunkChild, &JunkX, &JunkY, &x, &y, + &JunkMask); + Scroll(icon_w, icon_h, x, y, -1); + } } - } - if(Event->xany.window == icon_win) - { - XQueryPointer(dpy, icon_win, &JunkRoot, &JunkChild, - &JunkX, &JunkY,&x, &y, &JunkMask); - Scroll(icon_w, icon_h, x, y, -1); - } - } - break; - case ButtonPress: - if ( ShowBalloons ) - UnmapBalloonWindow(); - if (((Event->xbutton.button == 2)|| - ((Event->xbutton.button == 3)&& - (Event->xbutton.state & Mod1Mask)))&& - (Event->xbutton.subwindow != None)) - { - MoveWindow(Event); - } - else if (Event->xbutton.button == 3) - { - for(i=0;ixany.window == Desks[i].w) - { - if (Scr.CurrentDesk != i + desk1) - { - SwitchToDeskAndPage(i,Event); - Scr.CurrentDesk = i + desk1; - Wait = 0; - } - XQueryPointer(dpy, Desks[i].w, &JunkRoot, &JunkChild, - &JunkX, &JunkY,&x, &y, &JunkMask); - Scroll(desk_w, desk_h, x, y, i); - break; + break; + case ButtonPress: + if (ShowBalloons) + UnmapBalloonWindow(); + if (((Event->xbutton.button == 2) || + ((Event->xbutton.button == 3) && + (Event->xbutton.state & Mod1Mask))) && + (Event->xbutton.subwindow != None)) { + MoveWindow(Event); + } else if (Event->xbutton.button == 3) { + for (i = 0; i < ndesks; i++) { + if (Event->xany.window == Desks[i].w) { + if (Scr.CurrentDesk != i + desk1) { + SwitchToDeskAndPage(i, Event); + Scr.CurrentDesk = i + desk1; + Wait = 0; + } + XQueryPointer(dpy, Desks[i].w, + &JunkRoot, &JunkChild, &JunkX, + &JunkY, &x, &y, &JunkMask); + Scroll(desk_w, desk_h, x, y, i); + break; + } + } + if (Event->xany.window == icon_win) { + XQueryPointer(dpy, icon_win, &JunkRoot, + &JunkChild, &JunkX, &JunkY, &x, &y, + &JunkMask); + Scroll(icon_w, icon_h, x, y, -1); + } } - } - if(Event->xany.window == icon_win) - { - XQueryPointer(dpy, icon_win, &JunkRoot, &JunkChild, - &JunkX, &JunkY,&x, &y, &JunkMask); - Scroll(icon_w, icon_h, x, y, -1); - } - } - break; - case MotionNotify: - while(XCheckMaskEvent(dpy, PointerMotionMask | ButtonMotionMask,Event)); - - if(Event->xmotion.state == Button3MotionMask) - { - for(i=0;ixany.window == Desks[i].w) - { - XQueryPointer(dpy, Desks[i].w, &JunkRoot, &JunkChild, - &JunkX, &JunkY,&x, &y, &JunkMask); - Scroll(desk_w, desk_h, x, y, i); + break; + case MotionNotify: + while (XCheckMaskEvent( + dpy, PointerMotionMask | ButtonMotionMask, Event)) + ; + + if (Event->xmotion.state == Button3MotionMask) { + for (i = 0; i < ndesks; i++) { + if (Event->xany.window == Desks[i].w) { + XQueryPointer(dpy, Desks[i].w, + &JunkRoot, &JunkChild, &JunkX, + &JunkY, &x, &y, &JunkMask); + Scroll(desk_w, desk_h, x, y, i); + } + } + if (Event->xany.window == icon_win) { + XQueryPointer(dpy, icon_win, &JunkRoot, + &JunkChild, &JunkX, &JunkY, &x, &y, + &JunkMask); + Scroll(icon_w, icon_h, x, y, -1); + } } - } - if(Event->xany.window == icon_win) - { - XQueryPointer(dpy, icon_win, &JunkRoot, &JunkChild, - &JunkX, &JunkY,&x, &y, &JunkMask); - Scroll(icon_w, icon_h, x, y, -1); - } + break; + case ClientMessage: + if ((Event->xclient.format == 32) && + (Event->xclient.data.l[0] == wm_del_win)) { + exit(0); + } + break; } - break; - - case ClientMessage: - if ((Event->xclient.format==32) && - (Event->xclient.data.l[0]==wm_del_win)) - { - exit(0); - } - break; - } } -void HandleExpose(XEvent *Event) +void +HandleExpose(XEvent *Event) { - int i; - PagerWindow *t; - - /* ric@giccs.georgetown.edu */ - if ( Event->xany.window == balloon.w ) { - DrawInBalloonWindow(); - return; - } - - for(i=0;ixany.window == Desks[i].w) - ||(Event->xany.window == Desks[i].title_w)) - DrawGrid(i,0); - } - if(Event->xany.window == icon_win) - DrawIconGrid(0); - - t = Start; - while(t!= NULL) - { - if(t->PagerView == Event->xany.window) - { - LabelWindow(t); - PictureWindow(t); + int i; + PagerWindow *t; + + /* ric@giccs.georgetown.edu */ + if (Event->xany.window == balloon.w) { + DrawInBalloonWindow(); + return; } - else if(t->IconView == Event->xany.window) - { - LabelIconWindow(t); - PictureIconWindow(t); + + for (i = 0; i < ndesks; i++) { + if ((Event->xany.window == Desks[i].w) || + (Event->xany.window == Desks[i].title_w)) + DrawGrid(i, 0); } + if (Event->xany.window == icon_win) + DrawIconGrid(0); + + t = Start; + while (t != NULL) { + if (t->PagerView == Event->xany.window) { + LabelWindow(t); + PictureWindow(t); + } else if (t->IconView == Event->xany.window) { + LabelIconWindow(t); + PictureIconWindow(t); + } - t = t->next; - } + t = t->next; + } } - /**************************************************************************** * * Respond to a change in window geometry. * ****************************************************************************/ -void ReConfigure(void) +void +ReConfigure(void) { - Window root; - unsigned border_width, depth; - int n,m,w,h,n1,m1,x,y,i,j,k; - - - XGetGeometry(dpy,Scr.Pager_w,&root,&x,&y, - (unsigned *)&window_w,(unsigned *)&window_h, - &border_width,&depth); - - - n1 = Scr.Vx/Scr.MyDisplayWidth; - m1 = Scr.Vy/Scr.MyDisplayHeight; - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - desk_w = (window_w - Columns + 1)/Columns; - desk_h = (window_h - Rows*label_h - Rows + 2)/Rows; - w = (desk_w - n)/(n+1); - h = (desk_h - m)/(m+1); - - sizehints.width_inc = Columns*(n+1); - sizehints.height_inc = Rows*(m+1); - sizehints.base_width = Columns * n + Columns - 1; - sizehints.base_height = Rows*(m + label_h+1) -2; - sizehints.min_width = Columns * n + Columns - 1; - sizehints.min_height = Rows*(m + label_h+1) -2; - - XSetWMNormalHints(dpy,Scr.Pager_w,&sizehints); - - x = (desk_w-n)* Scr.Vx/(Scr.VxMax+Scr.MyDisplayWidth) +n1; - y = (desk_h-m)*Scr.Vy/(Scr.VyMax+Scr.MyDisplayHeight) +m1; - - for(k=0;k= desk1)&&(Scr.CurrentDesk <=desk2)) - sptr = Desks[Scr.CurrentDesk -desk1].label; - else - { - sprintf(str,"Desk %d",Scr.CurrentDesk); - sptr = &str[0]; + int n1, m1, x, y, n, m, i; + XTextProperty name; + char str[100], *sptr; + static int icon_desk_shown = -1000; + + Wait = 0; + n1 = Scr.Vx / Scr.MyDisplayWidth; + m1 = Scr.Vy / Scr.MyDisplayHeight; + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + + x = (desk_w - n) * Scr.Vx / (Scr.VxMax + Scr.MyDisplayWidth) + n1; + y = (desk_h - m) * Scr.Vy / (Scr.VyMax + Scr.MyDisplayHeight) + m1; + for (i = 0; i < ndesks; i++) { + if (i == Scr.CurrentDesk - desk1) { + XMoveWindow(dpy, Desks[i].CPagerWin, x, y); + XLowerWindow(dpy, Desks[i].CPagerWin); + } else + XMoveWindow(dpy, Desks[i].CPagerWin, -1000, -1000); } - if (XStringListToTextProperty(&sptr,1,&name) == 0) - { - fprintf(stderr,"%s: cannot allocate window name",MyName); - return; + DrawIconGrid(1); + + ReConfigureIcons(); + + if (Scr.CurrentDesk != icon_desk_shown) { + icon_desk_shown = Scr.CurrentDesk; + + if ((Scr.CurrentDesk >= desk1) && (Scr.CurrentDesk <= desk2)) + sptr = Desks[Scr.CurrentDesk - desk1].label; + else { + snprintf(str, sizeof(str), "Desk %d", Scr.CurrentDesk); + sptr = &str[0]; + } + if (XStringListToTextProperty(&sptr, 1, &name) == 0) { + fprintf( + stderr, "%s: cannot allocate window name", MyName); + return; + } + XSetWMIconName(dpy, Scr.Pager_w, &name); } - XSetWMIconName(dpy,Scr.Pager_w,&name); - } } -void ReConfigureAll(void) +void +ReConfigureAll(void) { - PagerWindow *t; - - t = Start; - while(t!= NULL) - { - MoveResizePagerView(t); - t = t->next; - } + PagerWindow *t; + + t = Start; + while (t != NULL) { + MoveResizePagerView(t); + t = t->next; + } } -void ReConfigureIcons(void) +void +ReConfigureIcons(void) { - PagerWindow *t; - int x,y,w,h,n,m,n1,m1; - - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - - t = Start; - while(t!= NULL) - { - n1 = (Scr.Vx+t->x)/Scr.MyDisplayWidth; - m1 = (Scr.Vy+t->y)/Scr.MyDisplayHeight; - x = (Scr.Vx + t->x)*(icon_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(icon_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(icon_w-n)/ - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(icon_h-m)/ - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - - if (w < 1) - w = 1; - if (h < 1) - h = 1; - - t->icon_view_width = w; - t->icon_view_height = h; - if(Scr.CurrentDesk == t->desk) - XMoveResizeWindow(dpy,t->IconView,x,y,w,h); - else - XMoveResizeWindow(dpy,t->IconView,-1000,-1000,w,h); - t = t->next; - } + PagerWindow *t; + int x, y, w, h, n, m, n1, m1; + + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + + t = Start; + while (t != NULL) { + n1 = (Scr.Vx + t->x) / Scr.MyDisplayWidth; + m1 = (Scr.Vy + t->y) / Scr.MyDisplayHeight; + x = (Scr.Vx + t->x) * (icon_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (icon_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (icon_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (icon_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + + if (w < 1) + w = 1; + if (h < 1) + h = 1; + + t->icon_view_width = w; + t->icon_view_height = h; + if (Scr.CurrentDesk == t->desk) + XMoveResizeWindow(dpy, t->IconView, x, y, w, h); + else + XMoveResizeWindow(dpy, t->IconView, -1000, -1000, w, h); + t = t->next; + } } /**************************************************************************** @@ -864,1177 +802,1110 @@ void ReConfigureIcons(void) * Draw grid lines for desk #i * ****************************************************************************/ -void DrawGrid(int i, int erase) +void +DrawGrid(int i, int erase) { - int y, y1, y2, x, x1, x2,d,hor_off,w; - int MaxW,MaxH; - char str[15], *ptr; - - if((i < 0 ) ||(i >= ndesks)) - return; - - MaxW = (Scr.VxMax + Scr.MyDisplayWidth); - MaxH = Scr.VyMax + Scr.MyDisplayHeight; - - x = Scr.MyDisplayWidth; - y1 = 0; - y2 = desk_h; - while(x < MaxW) - { - x1 = x*desk_w/MaxW; - XDrawLine(dpy,Desks[i].w,DashedGC,x1,y1,x1,y2); - x += Scr.MyDisplayWidth; - } - - y = Scr.MyDisplayHeight; - x1 = 0; - x2 = desk_w; - while(y < MaxH) - { - y1 = y*(desk_h)/MaxH; - XDrawLine(dpy,Desks[i].w,DashedGC,x1,y1,x2,y1); - y += Scr.MyDisplayHeight; - } - if((Scr.CurrentDesk - desk1) == i) - { - if(uselabel) - XFillRectangle(dpy,Desks[i].title_w,HiliteGC, - 0,0,desk_w,label_h -1); - } - else - { - if(uselabel && erase) - XClearArea(dpy,Desks[i].title_w, - 0,0,desk_w,label_h - 1,False); - } - - d = desk1+i; - ptr = Desks[i].label; - w=XTextWidth(font,ptr,strlen(ptr)); - if( w > desk_w) - { - sprintf(str,"%d",d); - ptr = str; - w=XTextWidth(font,ptr,strlen(ptr)); - } - if((w<= desk_w)&&(uselabel)) - { - hor_off = (desk_w -w)/2; - if(i == (Scr.CurrentDesk - desk1)) - XDrawString (dpy, Desks[i].title_w,rvGC,hor_off,font->ascent +1 , - ptr, strlen(ptr)); - else - XDrawString (dpy, Desks[i].title_w,NormalGC,hor_off,font->ascent+1 , - ptr, strlen(ptr)); - } -} + int y, y1, y2, x, x1, x2, d, hor_off, w; + int MaxW, MaxH; + char str[15], *ptr; + + if ((i < 0) || (i >= ndesks)) + return; + + MaxW = (Scr.VxMax + Scr.MyDisplayWidth); + MaxH = Scr.VyMax + Scr.MyDisplayHeight; + + x = Scr.MyDisplayWidth; + y1 = 0; + y2 = desk_h; + while (x < MaxW) { + x1 = x * desk_w / MaxW; + XDrawLine(dpy, Desks[i].w, DashedGC, x1, y1, x1, y2); + x += Scr.MyDisplayWidth; + } + y = Scr.MyDisplayHeight; + x1 = 0; + x2 = desk_w; + while (y < MaxH) { + y1 = y * (desk_h) / MaxH; + XDrawLine(dpy, Desks[i].w, DashedGC, x1, y1, x2, y1); + y += Scr.MyDisplayHeight; + } + if ((Scr.CurrentDesk - desk1) == i) { + if (uselabel) + XFillRectangle(dpy, Desks[i].title_w, HiliteGC, 0, 0, + desk_w, label_h - 1); + } else { + if (uselabel && erase) + XClearArea(dpy, Desks[i].title_w, 0, 0, desk_w, + label_h - 1, False); + } -void DrawIconGrid(int erase) + d = desk1 + i; + ptr = Desks[i].label; + w = XTextWidth(font, ptr, strlen(ptr)); + if (w > desk_w) { + snprintf(str, sizeof(str), "%d", d); + ptr = str; + w = XTextWidth(font, ptr, strlen(ptr)); + } + if ((w <= desk_w) && (uselabel)) { + hor_off = (desk_w - w) / 2; + if (i == (Scr.CurrentDesk - desk1)) + XDrawString(dpy, Desks[i].title_w, rvGC, hor_off, + font->ascent + 1, ptr, strlen(ptr)); + else + XDrawString(dpy, Desks[i].title_w, NormalGC, hor_off, + font->ascent + 1, ptr, strlen(ptr)); + } +} + +void +DrawIconGrid(int erase) { - int y, y1, y2, x, x1, x2,w,h,n,m,n1,m1; - int MaxW,MaxH; - - MaxW = (Scr.VxMax + Scr.MyDisplayWidth); - MaxH = Scr.VyMax + Scr.MyDisplayHeight; - - if(erase) - XClearWindow(dpy,icon_win); - x = Scr.MyDisplayWidth; - y1 = 0; - y2 = icon_h; - while(x < MaxW) - { - x1 = x*icon_w/MaxW; - XDrawLine(dpy,icon_win,DashedGC,x1,y1,x1,y2); - x += Scr.MyDisplayWidth; - } - - y = Scr.MyDisplayHeight; - x1 = 0; - x2 = icon_w; - while(y < MaxH) - { - y1 = y*(icon_h)/MaxH; - XDrawLine(dpy,icon_win,DashedGC,x1,y1,x2,y1); - y += Scr.MyDisplayHeight; - } - n1 = Scr.Vx/Scr.MyDisplayWidth; - m1 = Scr.Vy/Scr.MyDisplayHeight; - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - w = (icon_w - n)/(n+1); - h = (icon_h - m)/(m+1); - - x = (icon_w-n)* Scr.Vx/(Scr.VxMax+Scr.MyDisplayWidth) +n1; - y = (icon_h-m)*Scr.Vy/(Scr.VyMax+Scr.MyDisplayHeight) +m1; - - XFillRectangle(dpy,icon_win,HiliteGC, - x,y,w,h); + int y, y1, y2, x, x1, x2, w, h, n, m, n1, m1; + int MaxW, MaxH; + + MaxW = (Scr.VxMax + Scr.MyDisplayWidth); + MaxH = Scr.VyMax + Scr.MyDisplayHeight; + + if (erase) + XClearWindow(dpy, icon_win); + x = Scr.MyDisplayWidth; + y1 = 0; + y2 = icon_h; + while (x < MaxW) { + x1 = x * icon_w / MaxW; + XDrawLine(dpy, icon_win, DashedGC, x1, y1, x1, y2); + x += Scr.MyDisplayWidth; + } -} + y = Scr.MyDisplayHeight; + x1 = 0; + x2 = icon_w; + while (y < MaxH) { + y1 = y * (icon_h) / MaxH; + XDrawLine(dpy, icon_win, DashedGC, x1, y1, x2, y1); + y += Scr.MyDisplayHeight; + } + n1 = Scr.Vx / Scr.MyDisplayWidth; + m1 = Scr.Vy / Scr.MyDisplayHeight; + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + w = (icon_w - n) / (n + 1); + h = (icon_h - m) / (m + 1); + x = (icon_w - n) * Scr.Vx / (Scr.VxMax + Scr.MyDisplayWidth) + n1; + y = (icon_h - m) * Scr.Vy / (Scr.VyMax + Scr.MyDisplayHeight) + m1; -void SwitchToDesk(int Desk) + XFillRectangle(dpy, icon_win, HiliteGC, x, y, w, h); +} + +void +SwitchToDesk(int Desk) { - char command[256]; + char command[256]; - sprintf(command,"Desk 0 %d\n",Desk+desk1); + snprintf(command, sizeof(command), "Desk 0 %d\n", Desk + desk1); - SendInfo(fd,command,0); + SendInfo(fd, command, 0); } - -void SwitchToDeskAndPage(int Desk, XEvent *Event) +void +SwitchToDeskAndPage(int Desk, XEvent *Event) { #ifndef NON_VIRTUAL - char command[256]; - - if (Scr.CurrentDesk != (Desk+desk1)) - { - int vx, vy; - SendInfo(fd,"Desk 0 10000\n",0); - /* patch to let mouse button 3 change desks and do not cling to a page */ - vx = Event->xbutton.x*(Scr.VxMax+Scr.MyDisplayWidth)/ - (desk_w*Scr.MyDisplayWidth); - vy = Event->xbutton.y*(Scr.VyMax+Scr.MyDisplayHeight)/ - (desk_h*Scr.MyDisplayHeight); - Scr.Vx = vx * Scr.MyDisplayWidth; - Scr.Vy = vy * Scr.MyDisplayHeight; - sprintf(command,"GotoPage %d %d\n", vx, vy); - SendInfo(fd,command,0); - sprintf(command,"Desk 0 %d\n",Desk+desk1); - SendInfo(fd,command,0); - - } - else - { - sprintf(command,"GotoPage %d %d\n", - Event->xbutton.x*(Scr.VxMax+Scr.MyDisplayWidth)/ - (desk_w*Scr.MyDisplayWidth), - Event->xbutton.y*(Scr.VyMax+Scr.MyDisplayHeight)/ - (desk_h*Scr.MyDisplayHeight)); - SendInfo(fd,command,0); - } + char command[256]; + + if (Scr.CurrentDesk != (Desk + desk1)) { + int vx, vy; + SendInfo(fd, "Desk 0 10000\n", 0); + /* patch to let mouse button 3 change desks and do not cling to + * a page */ + vx = Event->xbutton.x * (Scr.VxMax + Scr.MyDisplayWidth) / + (desk_w * Scr.MyDisplayWidth); + vy = Event->xbutton.y * (Scr.VyMax + Scr.MyDisplayHeight) / + (desk_h * Scr.MyDisplayHeight); + Scr.Vx = vx * Scr.MyDisplayWidth; + Scr.Vy = vy * Scr.MyDisplayHeight; + snprintf(command, sizeof(command), "GotoPage %d %d\n", vx, vy); + SendInfo(fd, command, 0); + snprintf(command, sizeof(command), "Desk 0 %d\n", Desk + desk1); + SendInfo(fd, command, 0); + } else { + snprintf(command, sizeof(command), "GotoPage %d %d\n", + Event->xbutton.x * (Scr.VxMax + Scr.MyDisplayWidth) / + (desk_w * Scr.MyDisplayWidth), + Event->xbutton.y * (Scr.VyMax + Scr.MyDisplayHeight) / + (desk_h * Scr.MyDisplayHeight)); + SendInfo(fd, command, 0); + } #endif - Wait = 1; + Wait = 1; } -void IconSwitchPage(XEvent *Event) +void +IconSwitchPage(XEvent *Event) { #ifndef NON_VIRTUAL - char command[256]; - - sprintf(command,"GotoPage %d %d\n", - Event->xbutton.x*(Scr.VxMax+Scr.MyDisplayWidth)/ - (icon_w*Scr.MyDisplayWidth), - Event->xbutton.y*(Scr.VyMax+Scr.MyDisplayHeight)/ - (icon_h*Scr.MyDisplayHeight)); - SendInfo(fd,command,0); + char command[256]; + + snprintf(command, sizeof(command), "GotoPage %d %d\n", + Event->xbutton.x * (Scr.VxMax + Scr.MyDisplayWidth) / + (icon_w * Scr.MyDisplayWidth), + Event->xbutton.y * (Scr.VyMax + Scr.MyDisplayHeight) / + (icon_h * Scr.MyDisplayHeight)); + SendInfo(fd, command, 0); #endif - Wait = 1; + Wait = 1; } - -void AddNewWindow(PagerWindow *t) +void +AddNewWindow(PagerWindow *t) { - unsigned long valuemask; - XSetWindowAttributes attributes; - int i,x,y,w,h,n,m,n1,m1; - - i = t->desk - desk1; - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - n1 = (Scr.Vx+t->x)/Scr.MyDisplayWidth; - m1 = (Scr.Vy+t->y)/Scr.MyDisplayHeight; - x = (Scr.Vx + t->x)*(desk_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(desk_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(desk_w-n)/ - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(desk_h-m)/ - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - if(w<1) - w = 1; - if(h<1) - h = 1; - - t->pager_view_width = w; - t->pager_view_height = h; - valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); - attributes.background_pixel = t->back; - attributes.border_pixel = fore_pix; - attributes.event_mask = (ExposureMask); - - /* ric@giccs.georgetown.edu -- added Enter and Leave events for - popping up balloon window */ - attributes.event_mask = (ExposureMask | EnterWindowMask | LeaveWindowMask); - - if((i >= 0)&& (i PagerView = XCreateWindow(dpy,Desks[i].w, x, y, w, h,1, - CopyFromParent, - InputOutput,CopyFromParent, - valuemask,&attributes); - - XMapRaised(dpy,t->PagerView); - } - else - t->PagerView = None; - - - x = (Scr.Vx + t->x)*(icon_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(icon_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(icon_w-n)/ - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(icon_h-m)/ - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - if(w<1) - w = 1; - if(h<1) - h = 1; - - t->icon_view_width = w; - t->icon_view_height = h; - if(Scr.CurrentDesk == t->desk) - { - t->IconView = XCreateWindow(dpy,icon_win, x, y, w, h,1, - CopyFromParent, - InputOutput,CopyFromParent, - valuemask,&attributes); - XGrabButton(dpy, 2, AnyModifier, t->IconView, - True, ButtonPressMask | ButtonReleaseMask|ButtonMotionMask, - GrabModeAsync, GrabModeAsync, None, - None); - XMapRaised(dpy,t->IconView); - } - else - { - t->IconView = XCreateWindow(dpy,icon_win, -1000, -1000, w, h,1, - CopyFromParent, - InputOutput,CopyFromParent, - valuemask,&attributes); - XMapRaised(dpy,t->IconView); - } - Hilight(t,OFF); + unsigned long valuemask; + XSetWindowAttributes attributes; + int i, x, y, w, h, n, m, n1, m1; + + i = t->desk - desk1; + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + n1 = (Scr.Vx + t->x) / Scr.MyDisplayWidth; + m1 = (Scr.Vy + t->y) / Scr.MyDisplayHeight; + x = (Scr.Vx + t->x) * (desk_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (desk_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (desk_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (desk_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + if (w < 1) + w = 1; + if (h < 1) + h = 1; + + t->pager_view_width = w; + t->pager_view_height = h; + valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); + attributes.background_pixel = t->back; + attributes.border_pixel = fore_pix; + attributes.event_mask = (ExposureMask); + + /* ric@giccs.georgetown.edu -- added Enter and Leave events for + popping up balloon window */ + attributes.event_mask = + (ExposureMask | EnterWindowMask | LeaveWindowMask); + + if ((i >= 0) && (i < ndesks)) { + t->PagerView = XCreateWindow(dpy, Desks[i].w, x, y, w, h, 1, + CopyFromParent, InputOutput, CopyFromParent, valuemask, + &attributes); + + XMapRaised(dpy, t->PagerView); + } else + t->PagerView = None; + + x = (Scr.Vx + t->x) * (icon_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (icon_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (icon_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (icon_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + if (w < 1) + w = 1; + if (h < 1) + h = 1; + + t->icon_view_width = w; + t->icon_view_height = h; + if (Scr.CurrentDesk == t->desk) { + t->IconView = + XCreateWindow(dpy, icon_win, x, y, w, h, 1, CopyFromParent, + InputOutput, CopyFromParent, valuemask, &attributes); + XGrabButton(dpy, 2, AnyModifier, t->IconView, True, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, + GrabModeAsync, GrabModeAsync, None, None); + XMapRaised(dpy, t->IconView); + } else { + t->IconView = XCreateWindow(dpy, icon_win, -1000, -1000, w, h, + 1, CopyFromParent, InputOutput, CopyFromParent, valuemask, + &attributes); + XMapRaised(dpy, t->IconView); + } + Hilight(t, OFF); } +void +ChangeDeskForWindow(PagerWindow *t, long newdesk) +{ + int i, x, y, w, h, n, m, n1, m1; + i = newdesk - desk1; -void ChangeDeskForWindow(PagerWindow *t,long newdesk) -{ - int i,x,y,w,h,n,m,n1,m1; - - i = newdesk - desk1; - - if(t->PagerView == None) - { - t->desk = newdesk; - XDestroyWindow(dpy,t->IconView); - AddNewWindow( t); - return; - } - - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - n1 = (Scr.Vx+t->x)/Scr.MyDisplayWidth; - m1 = (Scr.Vy+t->y)/Scr.MyDisplayHeight; - x = (Scr.Vx + t->x)*(desk_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(desk_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(desk_w-n) / - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(desk_h-m) / - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - if (w < 1) - w = 1; - if (h < 1) - h = 1; - t->pager_view_width = w; - t->pager_view_height = h; - if((i >= 0)&&(i < ndesks)) - { - XReparentWindow(dpy, t->PagerView, Desks[i].w, x,y); - XResizeWindow(dpy,t->PagerView,w,h); - } - else - { - XDestroyWindow(dpy,t->PagerView); - t->PagerView = None; - } - t->desk = i+desk1; - - x = (Scr.Vx + t->x)*(icon_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(icon_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(icon_w-n) / - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(icon_h-m) / - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - if (w < 1) - w = 1; - if (h < 1) - h = 1; - t->icon_view_width = w; - t->icon_view_height = h; - if(Scr.CurrentDesk == t->desk) - XMoveResizeWindow(dpy,t->IconView,x,y,w,h); - else - XMoveResizeWindow(dpy,t->IconView,-1000,-1000,w,h); + if (t->PagerView == None) { + t->desk = newdesk; + XDestroyWindow(dpy, t->IconView); + AddNewWindow(t); + return; + } + + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + n1 = (Scr.Vx + t->x) / Scr.MyDisplayWidth; + m1 = (Scr.Vy + t->y) / Scr.MyDisplayHeight; + x = (Scr.Vx + t->x) * (desk_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (desk_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (desk_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (desk_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + if (w < 1) + w = 1; + if (h < 1) + h = 1; + t->pager_view_width = w; + t->pager_view_height = h; + if ((i >= 0) && (i < ndesks)) { + XReparentWindow(dpy, t->PagerView, Desks[i].w, x, y); + XResizeWindow(dpy, t->PagerView, w, h); + } else { + XDestroyWindow(dpy, t->PagerView); + t->PagerView = None; + } + t->desk = i + desk1; + + x = (Scr.Vx + t->x) * (icon_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (icon_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (icon_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (icon_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + if (w < 1) + w = 1; + if (h < 1) + h = 1; + t->icon_view_width = w; + t->icon_view_height = h; + if (Scr.CurrentDesk == t->desk) + XMoveResizeWindow(dpy, t->IconView, x, y, w, h); + else + XMoveResizeWindow(dpy, t->IconView, -1000, -1000, w, h); } -void MoveResizePagerView(PagerWindow *t) +void +MoveResizePagerView(PagerWindow *t) { - int x,y,w,h,n,m,n1,m1; - - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - n1 = (Scr.Vx+t->x)/Scr.MyDisplayWidth; - m1 = (Scr.Vy+t->y)/Scr.MyDisplayHeight; - x = (Scr.Vx + t->x)*(desk_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(desk_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(desk_w-n)/ - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(desk_h-m)/ - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - - if (w < 1) - w = 1; - if (h < 1) - h = 1; - t->pager_view_width = w; - t->pager_view_height = h; - if(t->PagerView != None) - XMoveResizeWindow(dpy,t->PagerView,x,y,w,h); - else if((t->desk >= desk1)&&(t->desk <= desk2)) - { - XDestroyWindow(dpy,t->IconView); - AddNewWindow(t); - return; - } - - x = (Scr.Vx + t->x)*(icon_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(icon_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(icon_w-n)/ - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(icon_h-m)/ - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - - if (w < 1) - w = 1; - if (h < 1) - h = 1; - t->icon_view_width = w; - t->icon_view_height = h; - if(Scr.CurrentDesk == t->desk) - XMoveResizeWindow(dpy,t->IconView,x,y,w,h); - else - XMoveResizeWindow(dpy,t->IconView,-1000,-1000,w,h); -} + int x, y, w, h, n, m, n1, m1; + + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + n1 = (Scr.Vx + t->x) / Scr.MyDisplayWidth; + m1 = (Scr.Vy + t->y) / Scr.MyDisplayHeight; + x = (Scr.Vx + t->x) * (desk_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (desk_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (desk_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (desk_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + + if (w < 1) + w = 1; + if (h < 1) + h = 1; + t->pager_view_width = w; + t->pager_view_height = h; + if (t->PagerView != None) + XMoveResizeWindow(dpy, t->PagerView, x, y, w, h); + else if ((t->desk >= desk1) && (t->desk <= desk2)) { + XDestroyWindow(dpy, t->IconView); + AddNewWindow(t); + return; + } + x = (Scr.Vx + t->x) * (icon_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (icon_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (icon_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (icon_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + + if (w < 1) + w = 1; + if (h < 1) + h = 1; + t->icon_view_width = w; + t->icon_view_height = h; + if (Scr.CurrentDesk == t->desk) + XMoveResizeWindow(dpy, t->IconView, x, y, w, h); + else + XMoveResizeWindow(dpy, t->IconView, -1000, -1000, w, h); +} -void MoveStickyWindows(void) +void +MoveStickyWindows(void) { - PagerWindow *t; - - t = Start; - while(t!= NULL) - { - if(((t->flags & ICONIFIED)&&(t->flags & StickyIcon))|| - (t->flags & STICKY)) - { - if(t->desk != Scr.CurrentDesk) - { - ChangeDeskForWindow(t,Scr.CurrentDesk); - } - else - { - MoveResizePagerView(t); - - } + PagerWindow *t; + + t = Start; + while (t != NULL) { + if (((t->flags & ICONIFIED) && (t->flags & StickyIcon)) || + (t->flags & STICKY)) { + if (t->desk != Scr.CurrentDesk) { + ChangeDeskForWindow(t, Scr.CurrentDesk); + } else { + MoveResizePagerView(t); + } + } + t = t->next; } - t = t->next; - } } -void Hilight(PagerWindow *t, int on) +void +Hilight(PagerWindow *t, int on) { - if(!t)return; - - if(Scr.d_depth < 2) - { - if(on) - { - if(t->PagerView != None) - XSetWindowBackgroundPixmap(dpy,t->PagerView,Scr.gray_pixmap); - XSetWindowBackgroundPixmap(dpy,t->IconView,Scr.gray_pixmap); - } - else - { - if(t->flags & STICKY) - { - if(t->PagerView != None) - XSetWindowBackgroundPixmap(dpy,t->PagerView, - Scr.sticky_gray_pixmap); - XSetWindowBackgroundPixmap(dpy,t->IconView, - Scr.sticky_gray_pixmap); - } - else - { - if(t->PagerView != None) - XSetWindowBackgroundPixmap(dpy,t->PagerView, - Scr.light_gray_pixmap); - XSetWindowBackgroundPixmap(dpy,t->IconView, - Scr.light_gray_pixmap); - } - } - } - else - { - if(on) - { - if(t->PagerView != None) - XSetWindowBackground(dpy,t->PagerView,focus_pix); - XSetWindowBackground(dpy,t->IconView,focus_pix); - } - else - { - if(t->PagerView != None) - XSetWindowBackground(dpy,t->PagerView,t->back); - XSetWindowBackground(dpy,t->IconView,t->back); + if (!t) + return; + + if (Scr.d_depth < 2) { + if (on) { + if (t->PagerView != None) + XSetWindowBackgroundPixmap( + dpy, t->PagerView, Scr.gray_pixmap); + XSetWindowBackgroundPixmap( + dpy, t->IconView, Scr.gray_pixmap); + } else { + if (t->flags & STICKY) { + if (t->PagerView != None) + XSetWindowBackgroundPixmap(dpy, + t->PagerView, + Scr.sticky_gray_pixmap); + XSetWindowBackgroundPixmap( + dpy, t->IconView, Scr.sticky_gray_pixmap); + } else { + if (t->PagerView != None) + XSetWindowBackgroundPixmap(dpy, + t->PagerView, + Scr.light_gray_pixmap); + XSetWindowBackgroundPixmap( + dpy, t->IconView, Scr.light_gray_pixmap); + } + } + } else { + if (on) { + if (t->PagerView != None) + XSetWindowBackground( + dpy, t->PagerView, focus_pix); + XSetWindowBackground(dpy, t->IconView, focus_pix); + } else { + if (t->PagerView != None) + XSetWindowBackground( + dpy, t->PagerView, t->back); + XSetWindowBackground(dpy, t->IconView, t->back); + } } - } - if(t->PagerView != None) - XClearWindow(dpy,t->PagerView); - XClearWindow(dpy,t->IconView); - LabelWindow(t); - LabelIconWindow(t); - PictureWindow(t); - PictureIconWindow(t); + if (t->PagerView != None) + XClearWindow(dpy, t->PagerView); + XClearWindow(dpy, t->IconView); + LabelWindow(t); + LabelIconWindow(t); + PictureWindow(t); + PictureIconWindow(t); } /* Use Desk == -1 to scroll the icon window */ -void Scroll(int window_w, int window_h, int x, int y, int Desk) +void +Scroll(int window_w, int window_h, int x, int y, int Desk) { #ifndef NON_VIRTUAL - char command[256]; - int sx, sy; - if(Wait == 0) - { - /* Desk < 0 means we want to scroll an icon window */ - if(Desk >= 0 && Desk + desk1 != Scr.CurrentDesk) - { - return; - } + char command[256]; + int sx, sy; + if (Wait == 0) { + /* Desk < 0 means we want to scroll an icon window */ + if (Desk >= 0 && Desk + desk1 != Scr.CurrentDesk) { + return; + } - if(x < 0) - x = 0; - if(y < 0) - y = 0; - - if(x > window_w) - x = window_w; - if(y > window_h) - y = window_h; - - sx = (100*(x*(Scr.VxMax+Scr.MyDisplayWidth)/window_w- Scr.Vx)) / - Scr.MyDisplayWidth; - sy = (100*(y*(Scr.VyMax+Scr.MyDisplayHeight)/window_h - Scr.Vy)) / - Scr.MyDisplayHeight; - /* Make sure we don't get stuck a few pixels fromt the top/left border. - * Since sx/sy are ints, values between 0 and 1 are rounded down. */ - if(sx == 0 && x == 0 && Scr.Vx != 0) sx = -1; - if(sy == 0 && y == 0 && Scr.Vy != 0) sy = -1; - - sprintf(command,"Scroll %d %d\n",sx,sy); - SendInfo(fd,command,0); - Wait = 1; - } + if (x < 0) + x = 0; + if (y < 0) + y = 0; + + if (x > window_w) + x = window_w; + if (y > window_h) + y = window_h; + + sx = (100 * (x * (Scr.VxMax + Scr.MyDisplayWidth) / window_w - + Scr.Vx)) / + Scr.MyDisplayWidth; + sy = (100 * (y * (Scr.VyMax + Scr.MyDisplayHeight) / window_h - + Scr.Vy)) / + Scr.MyDisplayHeight; + /* Make sure we don't get stuck a few pixels fromt the top/left + * border. Since sx/sy are ints, values between 0 and 1 are + * rounded down. */ + if (sx == 0 && x == 0 && Scr.Vx != 0) + sx = -1; + if (sy == 0 && y == 0 && Scr.Vy != 0) + sy = -1; + + snprintf(command, sizeof(command), "Scroll %d %d\n", sx, sy); + SendInfo(fd, command, 0); + Wait = 1; + } #endif } -void MoveWindow(XEvent *Event) +void +MoveWindow(XEvent *Event) { - char command[100]; - int x1,y1,finished = 0,wx,wy,n,x,y,xi=0,yi=0,wx1,wy1,x2,y2; - Window dumwin; - PagerWindow *t; - int m,n1,m1; - int NewDesk,KeepMoving = 0; - int moved = 0; - int row,column; - - t = Start; - while ((t != NULL)&&(t->PagerView != Event->xbutton.subwindow)) - t= t->next; - - if(t==NULL) - { - t = Start; - while ((t != NULL)&&(t->IconView != Event->xbutton.subwindow)) - t= t->next; - if(t!=NULL) - { - IconMoveWindow(Event,t); - return; - } - } - - if(t == NULL) - return; - - NewDesk = t->desk - desk1; - if((NewDesk < 0)||(NewDesk >= ndesks)) - return; - - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - n1 = (Scr.Vx+t->x)/Scr.MyDisplayWidth; - m1 = (Scr.Vy+t->y)/Scr.MyDisplayHeight; - wx = (Scr.Vx + t->x)*(desk_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - wy = (Scr.Vy + t->y)*(desk_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - wx1 = wx+(desk_w+1)*(NewDesk%Columns); - wy1 = wy + label_h + (desk_h+label_h+1)*(NewDesk/Columns); - - XReparentWindow(dpy, t->PagerView, Scr.Pager_w,wx1,wy1); - XRaiseWindow(dpy,t->PagerView); - - XTranslateCoordinates(dpy, Event->xany.window, t->PagerView, - Event->xbutton.x, Event->xbutton.y, &x1, &y1, &dumwin); - xi = x1; - yi = y1; - while(!finished) - { - XMaskEvent(dpy,ButtonReleaseMask | ButtonMotionMask|ExposureMask,Event); - - if(Event->type == MotionNotify) - { - XTranslateCoordinates(dpy, Event->xany.window, Scr.Pager_w, - Event->xmotion.x, Event->xmotion.y, &x, &y, - &dumwin); - if(moved == 0) - { - xi = x; - yi = y; - moved = 1; - } - if((x < -5)||(y<-5)||(x>window_w+5)||(y>window_h+5)) - { - KeepMoving = 1; - finished = 1; - } - XMoveWindow(dpy,t->PagerView, x - (x1), - y - (y1)); - } - else if(Event->type == ButtonRelease) - { - XTranslateCoordinates(dpy, Event->xany.window, Scr.Pager_w, - Event->xbutton.x, Event->xbutton.y, &x, &y, - &dumwin); - XMoveWindow(dpy,t->PagerView, x - (x1), - y - (y1)); - finished = 1; - } - else if (Event->type == Expose) - { - HandleExpose(Event); - } - } - - if(moved) - { - if((x - xi < 3)&&(y - yi < 3)&& - (x - xi > -3)&&(y -yi > -3)) - moved = 0; - } - if(KeepMoving) - { - NewDesk = Scr.CurrentDesk; - if(NewDesk != t->desk) - { - XMoveWindow(dpy,t->w,Scr.MyDisplayWidth+Scr.VxMax, - Scr.MyDisplayHeight+Scr.VyMax); - XSync(dpy,0); - sprintf(command,"MoveToDesk 0 %d", NewDesk); - SendInfo(fd,command,t->w); - t->desk = NewDesk; - } - if((NewDesk>=desk1)&&(NewDesk<=desk2)) - XReparentWindow(dpy, t->PagerView, Desks[NewDesk-desk1].w,0,0); - else - { - XDestroyWindow(dpy,t->PagerView); - t->PagerView = None; - } - XTranslateCoordinates(dpy, Scr.Pager_w, Scr.Root, - x, y, &x1, &y1, &dumwin); - XUngrabPointer(dpy,CurrentTime); - XSync(dpy,0); - sprintf(command, "Move %dp %dp", x, y); - SendInfo(fd,command,t->w); - SendInfo(fd,"Raise",t->w); - SendInfo(fd,"Move",t->w); - return; - } - else - { - column = (x/(desk_w+1)); - row = (y/(desk_h+ label_h+1)); - NewDesk = column + (row)*Columns; - if((NewDesk <0)||(NewDesk >=ndesks)) - { - NewDesk = Scr.CurrentDesk - desk1; - x = xi; - y = yi; - moved = 0; - } - XTranslateCoordinates(dpy, Scr.Pager_w,Desks[NewDesk].w, - x-x1, y-y1, &x2,&y2,&dumwin); - - n1 = x2*(Scr.VxMax + Scr.MyDisplayWidth)/(desk_w * Scr.MyDisplayWidth); - m1 = y2*(Scr.VyMax + Scr.MyDisplayHeight)/(desk_h * Scr.MyDisplayHeight); - x = (x2-n1)* - (Scr.VxMax + Scr.MyDisplayWidth)/(desk_w-n) - Scr.Vx; - y = (y2-m1)* - (Scr.VyMax + Scr.MyDisplayHeight)/(desk_h-m) - Scr.Vy; - if(x + t->frame_width + Scr.Vx < 0 ) - x = -Scr.Vx; - if(y+t->frame_height + Scr.Vy< 0) - y = -Scr.Vy; - if(x + Scr.Vx > Scr.MyDisplayWidth+Scr.VxMax) - x = Scr.MyDisplayWidth + Scr.VxMax - t->frame_width - Scr.Vx; - if(y +Scr.Vy> Scr.MyDisplayHeight+Scr.VyMax) - y = Scr.MyDisplayHeight+ Scr.VyMax - t->frame_height - Scr.Vy; - if(((t->flags & ICONIFIED)&&(t->flags & StickyIcon))|| - (t->flags & STICKY)) - { - NewDesk = Scr.CurrentDesk - desk1; - if(x > Scr.MyDisplayWidth -16) - x = Scr.MyDisplayWidth - 16; - if(y > Scr.MyDisplayHeight-16) - y = Scr.MyDisplayHeight - 16; - if(x + t->width < 16) - x = 16 - t->width; - if(y + t->height < 16) - y = 16 - t->height; + char command[100]; + int x1, y1, finished = 0, wx, wy, n, x, y, xi = 0, yi = 0, wx1, wy1, x2, + y2; + Window dumwin; + PagerWindow *t; + int m, n1, m1; + int NewDesk, KeepMoving = 0; + int moved = 0; + int row, column; + + t = Start; + while ((t != NULL) && (t->PagerView != Event->xbutton.subwindow)) + t = t->next; + + if (t == NULL) { + t = Start; + while ((t != NULL) && (t->IconView != Event->xbutton.subwindow)) + t = t->next; + if (t != NULL) { + IconMoveWindow(Event, t); + return; + } } - if(NewDesk +desk1 != t->desk) - { - if(((t->flags & ICONIFIED)&&(t->flags & StickyIcon))|| - (t->flags & STICKY)) - { - NewDesk = Scr.CurrentDesk - desk1; - if(t->desk != Scr.CurrentDesk) - ChangeDeskForWindow(t,Scr.CurrentDesk); - } - else - { - sprintf(command,"MoveToDesk 0 %d", NewDesk + desk1); - SendInfo(fd,command,t->w); - t->desk = NewDesk + desk1; - } + + if (t == NULL) + return; + + NewDesk = t->desk - desk1; + if ((NewDesk < 0) || (NewDesk >= ndesks)) + return; + + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + n1 = (Scr.Vx + t->x) / Scr.MyDisplayWidth; + m1 = (Scr.Vy + t->y) / Scr.MyDisplayHeight; + wx = (Scr.Vx + t->x) * (desk_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + wy = + (Scr.Vy + t->y) * (desk_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + wx1 = wx + (desk_w + 1) * (NewDesk % Columns); + wy1 = wy + label_h + (desk_h + label_h + 1) * (NewDesk / Columns); + + XReparentWindow(dpy, t->PagerView, Scr.Pager_w, wx1, wy1); + XRaiseWindow(dpy, t->PagerView); + + XTranslateCoordinates(dpy, Event->xany.window, t->PagerView, + Event->xbutton.x, Event->xbutton.y, &x1, &y1, &dumwin); + xi = x1; + yi = y1; + while (!finished) { + XMaskEvent(dpy, + ButtonReleaseMask | ButtonMotionMask | ExposureMask, Event); + + if (Event->type == MotionNotify) { + XTranslateCoordinates(dpy, Event->xany.window, + Scr.Pager_w, Event->xmotion.x, Event->xmotion.y, &x, + &y, &dumwin); + if (moved == 0) { + xi = x; + yi = y; + moved = 1; + } + if ((x < -5) || (y < -5) || (x > window_w + 5) || + (y > window_h + 5)) { + KeepMoving = 1; + finished = 1; + } + XMoveWindow(dpy, t->PagerView, x - (x1), y - (y1)); + } else if (Event->type == ButtonRelease) { + XTranslateCoordinates(dpy, Event->xany.window, + Scr.Pager_w, Event->xbutton.x, Event->xbutton.y, &x, + &y, &dumwin); + XMoveWindow(dpy, t->PagerView, x - (x1), y - (y1)); + finished = 1; + } else if (Event->type == Expose) { + HandleExpose(Event); + } } - if((NewDesk >= 0)&&(NewDesk < ndesks)) - { - XReparentWindow(dpy, t->PagerView, Desks[NewDesk].w,x,y); - if(moved) - { - if(t->flags & ICONIFIED) - XMoveWindow(dpy,t->icon_w,x,y); - else - XMoveWindow(dpy,t->w,x+t->border_width, - y+t->title_height+t->border_width); - XSync(dpy,0); - } - else - MoveResizePagerView(t); - SendInfo(fd,"Raise",t->w); + if (moved) { + if ((x - xi < 3) && (y - yi < 3) && (x - xi > -3) && + (y - yi > -3)) + moved = 0; } - if(Scr.CurrentDesk == t->desk) - { - XSync(dpy,0); - usleep(5000); - XSync(dpy,0); - if(t->flags & ICONIFIED) - { -/* - RBW - reverting to old code for 2.2... - The new handling causes an unwanted viewport change whenever Button2 - is used; the old handling causes focus to be sent to No Input windows - regardless of the Lenience setting. After 2.2 we will revisit this issue. - I suspect it will involve expanding the module message to include wmhints - and such. -*/ -#if 0 - SendInfo(fd, "Focus", t->icon_w); -#else - XSetInputFocus (dpy, t->icon_w, RevertToParent, - Event->xbutton.time); -#endif - } - else - { -#if 0 - SendInfo(fd, "Focus", t->w); -#else - XSetInputFocus (dpy, t->w, RevertToParent, - Event->xbutton.time); -#endif - } + if (KeepMoving) { + NewDesk = Scr.CurrentDesk; + if (NewDesk != t->desk) { + XMoveWindow(dpy, t->w, Scr.MyDisplayWidth + Scr.VxMax, + Scr.MyDisplayHeight + Scr.VyMax); + XSync(dpy, 0); + snprintf(command, sizeof(command), "MoveToDesk 0 %d", + NewDesk); + SendInfo(fd, command, t->w); + t->desk = NewDesk; + } + if ((NewDesk >= desk1) && (NewDesk <= desk2)) + XReparentWindow( + dpy, t->PagerView, Desks[NewDesk - desk1].w, 0, 0); + else { + XDestroyWindow(dpy, t->PagerView); + t->PagerView = None; + } + XTranslateCoordinates( + dpy, Scr.Pager_w, Scr.Root, x, y, &x1, &y1, &dumwin); + XUngrabPointer(dpy, CurrentTime); + XSync(dpy, 0); + snprintf(command, sizeof(command), "Move %dp %dp", x, y); + SendInfo(fd, command, t->w); + SendInfo(fd, "Raise", t->w); + SendInfo(fd, "Move", t->w); + return; + } else { + column = (x / (desk_w + 1)); + row = (y / (desk_h + label_h + 1)); + NewDesk = column + (row)*Columns; + if ((NewDesk < 0) || (NewDesk >= ndesks)) { + NewDesk = Scr.CurrentDesk - desk1; + x = xi; + y = yi; + moved = 0; + } + XTranslateCoordinates(dpy, Scr.Pager_w, Desks[NewDesk].w, + x - x1, y - y1, &x2, &y2, &dumwin); + + n1 = x2 * (Scr.VxMax + Scr.MyDisplayWidth) / + (desk_w * Scr.MyDisplayWidth); + m1 = y2 * (Scr.VyMax + Scr.MyDisplayHeight) / + (desk_h * Scr.MyDisplayHeight); + x = (x2 - n1) * (Scr.VxMax + Scr.MyDisplayWidth) / + (desk_w - n) - + Scr.Vx; + y = (y2 - m1) * (Scr.VyMax + Scr.MyDisplayHeight) / + (desk_h - m) - + Scr.Vy; + if (x + t->frame_width + Scr.Vx < 0) + x = -Scr.Vx; + if (y + t->frame_height + Scr.Vy < 0) + y = -Scr.Vy; + if (x + Scr.Vx > Scr.MyDisplayWidth + Scr.VxMax) + x = Scr.MyDisplayWidth + Scr.VxMax - t->frame_width - + Scr.Vx; + if (y + Scr.Vy > Scr.MyDisplayHeight + Scr.VyMax) + y = Scr.MyDisplayHeight + Scr.VyMax - t->frame_height - + Scr.Vy; + if (((t->flags & ICONIFIED) && (t->flags & StickyIcon)) || + (t->flags & STICKY)) { + NewDesk = Scr.CurrentDesk - desk1; + if (x > Scr.MyDisplayWidth - 16) + x = Scr.MyDisplayWidth - 16; + if (y > Scr.MyDisplayHeight - 16) + y = Scr.MyDisplayHeight - 16; + if (x + t->width < 16) + x = 16 - t->width; + if (y + t->height < 16) + y = 16 - t->height; + } + if (NewDesk + desk1 != t->desk) { + if (((t->flags & ICONIFIED) && + (t->flags & StickyIcon)) || + (t->flags & STICKY)) { + NewDesk = Scr.CurrentDesk - desk1; + if (t->desk != Scr.CurrentDesk) + ChangeDeskForWindow(t, Scr.CurrentDesk); + } else { + snprintf(command, sizeof(command), + "MoveToDesk 0 %d", NewDesk + desk1); + SendInfo(fd, command, t->w); + t->desk = NewDesk + desk1; + } + } + + if ((NewDesk >= 0) && (NewDesk < ndesks)) { + XReparentWindow( + dpy, t->PagerView, Desks[NewDesk].w, x, y); + if (moved) { + if (t->flags & ICONIFIED) + XMoveWindow(dpy, t->icon_w, x, y); + else + XMoveWindow(dpy, t->w, + x + t->border_width, + y + t->title_height + + t->border_width); + XSync(dpy, 0); + } else + MoveResizePagerView(t); + SendInfo(fd, "Raise", t->w); + } + if (Scr.CurrentDesk == t->desk) { + XSync(dpy, 0); + usleep(5000); + XSync(dpy, 0); + if (t->flags & ICONIFIED) { + /* + RBW - reverting to old code for 2.2... + The new handling causes an unwanted viewport + change whenever Button2 is used; the old + handling causes focus to be sent to No Input + windows regardless of the Lenience setting. + After 2.2 we will revisit this issue. I + suspect it will involve expanding the module + message to include wmhints and such. + */ + XSetInputFocus(dpy, t->icon_w, RevertToParent, + Event->xbutton.time); + } else { + XSetInputFocus(dpy, t->w, RevertToParent, + Event->xbutton.time); + } + } } - } } - - - - - /*********************************************************************** * * Procedure: * FvwmErrorHandler - displays info on internal errors * ************************************************************************/ -XErrorHandler FvwmErrorHandler(Display *dpy, XErrorEvent *event) +XErrorHandler +FvwmErrorHandler(Display *dpy, XErrorEvent *event) { -#if 1 - extern Bool error_occured; - error_occured = True; - return 0; -#else - /* really should just exit here... */ - /* domivogt (07-mar-1999): No, not really. See comment above. */ - fprintf(stderr,"%s: XError! Bagging out!\n",MyName); - exit(0); -#endif /* 1 */ + extern Bool error_occured; + error_occured = True; + return 0; } - -void LabelWindow(PagerWindow *t) +void +LabelWindow(PagerWindow *t) { - XGCValues Globalgcv; - unsigned long Globalgcm; - - if(windowFont == NULL) - { - return; - } - if (MiniIcons && t->mini_icon.picture && (t->PagerView != None)) - { - return; /* will draw picture instead... */ - } - if(t->icon_name == NULL) - { - return; - } - if(t == FocusWin) - { - Globalgcv.foreground = focus_fore_pix; - Globalgcv.background = focus_pix; - Globalgcm = GCForeground|GCBackground; - XChangeGC(dpy, StdGC,Globalgcm,&Globalgcv); - } - else - { - Globalgcv.foreground = t->text; - Globalgcv.background = t->back; - Globalgcm = GCForeground|GCBackground; - XChangeGC(dpy, StdGC,Globalgcm,&Globalgcv); - - } - if(t->PagerView != None) - { - XClearWindow(dpy, t->PagerView); - XDrawString (dpy, t->PagerView,StdGC,2,windowFont->ascent+2 , - t->icon_name, strlen(t->icon_name)); - } -} + XGCValues Globalgcv; + unsigned long Globalgcm; + if (windowFont == NULL) { + return; + } + if (MiniIcons && t->mini_icon.picture && (t->PagerView != None)) { + return; /* will draw picture instead... */ + } + if (t->icon_name == NULL) { + return; + } + if (t == FocusWin) { + Globalgcv.foreground = focus_fore_pix; + Globalgcv.background = focus_pix; + Globalgcm = GCForeground | GCBackground; + XChangeGC(dpy, StdGC, Globalgcm, &Globalgcv); + } else { + Globalgcv.foreground = t->text; + Globalgcv.background = t->back; + Globalgcm = GCForeground | GCBackground; + XChangeGC(dpy, StdGC, Globalgcm, &Globalgcv); + } + if (t->PagerView != None) { + XClearWindow(dpy, t->PagerView); + XDrawString(dpy, t->PagerView, StdGC, 2, windowFont->ascent + 2, + t->icon_name, strlen(t->icon_name)); + } +} -void LabelIconWindow(PagerWindow *t) +void +LabelIconWindow(PagerWindow *t) { - XGCValues Globalgcv; - unsigned long Globalgcm; - - if(windowFont == NULL) - { - return; - } - if (MiniIcons && t->mini_icon.picture && (t->PagerView != None)) - { - return; /* will draw picture instead... */ - } - if(t->icon_name == NULL) - { - return; - } - - if(t == FocusWin) - { - Globalgcv.foreground = focus_fore_pix; - Globalgcv.background = focus_pix; - Globalgcm = GCForeground|GCBackground; - XChangeGC(dpy,StdGC,Globalgcm,&Globalgcv); - } - else - { - Globalgcv.foreground = t->text; - Globalgcv.background = t->back; - Globalgcm = GCForeground|GCBackground; - XChangeGC(dpy,StdGC,Globalgcm,&Globalgcv); - - } - XClearWindow(dpy, t->IconView); - XDrawString (dpy, t->IconView,StdGC,2,windowFont->ascent+2 , - t->icon_name, strlen(t->icon_name)); + XGCValues Globalgcv; + unsigned long Globalgcm; + + if (windowFont == NULL) { + return; + } + if (MiniIcons && t->mini_icon.picture && (t->PagerView != None)) { + return; /* will draw picture instead... */ + } + if (t->icon_name == NULL) { + return; + } + if (t == FocusWin) { + Globalgcv.foreground = focus_fore_pix; + Globalgcv.background = focus_pix; + Globalgcm = GCForeground | GCBackground; + XChangeGC(dpy, StdGC, Globalgcm, &Globalgcv); + } else { + Globalgcv.foreground = t->text; + Globalgcv.background = t->back; + Globalgcm = GCForeground | GCBackground; + XChangeGC(dpy, StdGC, Globalgcm, &Globalgcv); + } + XClearWindow(dpy, t->IconView); + XDrawString(dpy, t->IconView, StdGC, 2, windowFont->ascent + 2, + t->icon_name, strlen(t->icon_name)); } -void PictureWindow (PagerWindow *t) + +void +PictureWindow(PagerWindow *t) { - XGCValues Globalgcv; - unsigned long Globalgcm; - int iconX; - int iconY; - if (MiniIcons) - { - if (t->mini_icon.picture && (t->PagerView != None)) - { - if (t->pager_view_width > t->mini_icon.width) - iconX = (t->pager_view_width - t->mini_icon.width) / 2; - else if (t->pager_view_width < t->mini_icon.width) - iconX = -((t->mini_icon.width - t->pager_view_width) / 2); - else - iconX = 0; - if (t->pager_view_height > t->mini_icon.height) - iconY = (t->pager_view_height - t->mini_icon.height) / 2; - else if (t->pager_view_height < t->mini_icon.height) - iconY = -((t->mini_icon.height - t->pager_view_height) / 2); - else - iconY = 0; - Globalgcm = GCForeground | GCBackground | GCClipMask | - GCClipXOrigin | GCClipYOrigin; - Globalgcv.clip_mask = t->mini_icon.mask; - Globalgcv.clip_x_origin = iconX; - Globalgcv.clip_y_origin = iconY; - if (t == FocusWin) - { - Globalgcv.foreground = focus_fore_pix; - Globalgcv.background = focus_pix; - } - else - { - Globalgcv.foreground = t->text; - Globalgcv.background = t->back; - } - XChangeGC (dpy, MiniIconGC, Globalgcm, &Globalgcv); - XClearWindow (dpy, t->PagerView); - XCopyArea (dpy, t->mini_icon.picture, t->PagerView, MiniIconGC, - 0, 0, t->mini_icon.width, t->mini_icon.height, iconX, - iconY); + XGCValues Globalgcv; + unsigned long Globalgcm; + int iconX; + int iconY; + if (MiniIcons) { + if (t->mini_icon.picture && (t->PagerView != None)) { + if (t->pager_view_width > t->mini_icon.width) + iconX = + (t->pager_view_width - t->mini_icon.width) / + 2; + else if (t->pager_view_width < t->mini_icon.width) + iconX = -( + (t->mini_icon.width - t->pager_view_width) / + 2); + else + iconX = 0; + if (t->pager_view_height > t->mini_icon.height) + iconY = (t->pager_view_height - + t->mini_icon.height) / + 2; + else if (t->pager_view_height < t->mini_icon.height) + iconY = -((t->mini_icon.height - + t->pager_view_height) / + 2); + else + iconY = 0; + Globalgcm = GCForeground | GCBackground | GCClipMask | + GCClipXOrigin | GCClipYOrigin; + Globalgcv.clip_mask = t->mini_icon.mask; + Globalgcv.clip_x_origin = iconX; + Globalgcv.clip_y_origin = iconY; + if (t == FocusWin) { + Globalgcv.foreground = focus_fore_pix; + Globalgcv.background = focus_pix; + } else { + Globalgcv.foreground = t->text; + Globalgcv.background = t->back; + } + XChangeGC(dpy, MiniIconGC, Globalgcm, &Globalgcv); + XClearWindow(dpy, t->PagerView); + XCopyArea(dpy, t->mini_icon.picture, t->PagerView, + MiniIconGC, 0, 0, t->mini_icon.width, + t->mini_icon.height, iconX, iconY); + } } - } } -void PictureIconWindow (PagerWindow *t) + +void +PictureIconWindow(PagerWindow *t) { - XGCValues Globalgcv; - unsigned long Globalgcm; - int iconX; - int iconY; - if (MiniIcons) - { - if (t->mini_icon.picture && (t->IconView != None)) - { - if (t->icon_view_width > t->mini_icon.width) - iconX = (t->icon_view_width - t->mini_icon.width) / 2; - else if (t->icon_view_width < t->mini_icon.width) - iconX = -((t->mini_icon.width - t->icon_view_width) / 2); - else - iconX = 0; - if (t->icon_view_height > t->mini_icon.height) - iconY = (t->icon_view_height - t->mini_icon.height) / 2; - else if (t->icon_view_height < t->mini_icon.height) - iconY = -((t->mini_icon.height - t->icon_view_height) / 2); - else - iconY = 0; - Globalgcm = GCForeground | GCBackground | GCClipMask | - GCClipXOrigin | GCClipYOrigin; - Globalgcv.clip_mask = t->mini_icon.mask; - Globalgcv.clip_x_origin = iconX; - Globalgcv.clip_y_origin = iconY; - if (t == FocusWin) - { - Globalgcv.foreground = focus_fore_pix; - Globalgcv.background = focus_pix; - } - else - { - Globalgcv.foreground = t->text; - Globalgcv.background = t->back; - } - XChangeGC (dpy, MiniIconGC, Globalgcm, &Globalgcv); - XClearWindow (dpy, t->IconView); - XCopyArea (dpy, t->mini_icon.picture, t->IconView, MiniIconGC, - 0, 0, t->mini_icon.width, t->mini_icon.height, iconX, - iconY); + XGCValues Globalgcv; + unsigned long Globalgcm; + int iconX; + int iconY; + if (MiniIcons) { + if (t->mini_icon.picture && (t->IconView != None)) { + if (t->icon_view_width > t->mini_icon.width) + iconX = + (t->icon_view_width - t->mini_icon.width) / + 2; + else if (t->icon_view_width < t->mini_icon.width) + iconX = -( + (t->mini_icon.width - t->icon_view_width) / + 2); + else + iconX = 0; + if (t->icon_view_height > t->mini_icon.height) + iconY = (t->icon_view_height - + t->mini_icon.height) / + 2; + else if (t->icon_view_height < t->mini_icon.height) + iconY = -((t->mini_icon.height - + t->icon_view_height) / + 2); + else + iconY = 0; + Globalgcm = GCForeground | GCBackground | GCClipMask | + GCClipXOrigin | GCClipYOrigin; + Globalgcv.clip_mask = t->mini_icon.mask; + Globalgcv.clip_x_origin = iconX; + Globalgcv.clip_y_origin = iconY; + if (t == FocusWin) { + Globalgcv.foreground = focus_fore_pix; + Globalgcv.background = focus_pix; + } else { + Globalgcv.foreground = t->text; + Globalgcv.background = t->back; + } + XChangeGC(dpy, MiniIconGC, Globalgcm, &Globalgcv); + XClearWindow(dpy, t->IconView); + XCopyArea(dpy, t->mini_icon.picture, t->IconView, + MiniIconGC, 0, 0, t->mini_icon.width, + t->mini_icon.height, iconX, iconY); + } } - } } -void IconMoveWindow(XEvent *Event,PagerWindow *t) +void +IconMoveWindow(XEvent *Event, PagerWindow *t) { - char command[100]; - int x1,y1,finished = 0,wx,wy,n,x=0,y=0,xi=0,yi=0; - Window dumwin; - int m,n1,m1; - int moved = 0; - int KeepMoving = 0; - - if(t==NULL) - return; - - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - n1 = (Scr.Vx+t->x)/Scr.MyDisplayWidth; - m1 = (Scr.Vy+t->y)/Scr.MyDisplayHeight; - wx = (Scr.Vx + t->x)*(icon_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - wy = (Scr.Vy + t->y)*(icon_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - - XRaiseWindow(dpy,t->IconView); - - XTranslateCoordinates(dpy, Event->xany.window, t->IconView, - Event->xbutton.x, Event->xbutton.y, &x1, &y1, &dumwin); - while(!finished) - { - XMaskEvent(dpy,ButtonReleaseMask | ButtonMotionMask|ExposureMask,Event); - - if(Event->type == MotionNotify) - { - x = Event->xbutton.x; - y = Event->xbutton.y; - if(moved == 0) - { - xi = x; - yi = y; - moved = 1; - } - - XMoveWindow(dpy,t->IconView, x - (x1), - y - (y1)); - if((x < -5)||(y < -5)||(x>icon_w+5)||(y>icon_h+5)) - { - finished = 1; - KeepMoving = 1; - } + char command[100]; + int x1, y1, finished = 0, wx, wy, n, x = 0, y = 0, xi = 0, yi = 0; + Window dumwin; + int m, n1, m1; + int moved = 0; + int KeepMoving = 0; + + if (t == NULL) + return; + + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + n1 = (Scr.Vx + t->x) / Scr.MyDisplayWidth; + m1 = (Scr.Vy + t->y) / Scr.MyDisplayHeight; + wx = (Scr.Vx + t->x) * (icon_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + wy = + (Scr.Vy + t->y) * (icon_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + + XRaiseWindow(dpy, t->IconView); + + XTranslateCoordinates(dpy, Event->xany.window, t->IconView, + Event->xbutton.x, Event->xbutton.y, &x1, &y1, &dumwin); + while (!finished) { + XMaskEvent(dpy, + ButtonReleaseMask | ButtonMotionMask | ExposureMask, Event); + + if (Event->type == MotionNotify) { + x = Event->xbutton.x; + y = Event->xbutton.y; + if (moved == 0) { + xi = x; + yi = y; + moved = 1; + } + + XMoveWindow(dpy, t->IconView, x - (x1), y - (y1)); + if ((x < -5) || (y < -5) || (x > icon_w + 5) || + (y > icon_h + 5)) { + finished = 1; + KeepMoving = 1; + } + } else if (Event->type == ButtonRelease) { + x = Event->xbutton.x; + y = Event->xbutton.y; + XMoveWindow(dpy, t->PagerView, x - (x1), y - (y1)); + finished = 1; + } else if (Event->type == Expose) { + HandleExpose(Event); + } } - else if(Event->type == ButtonRelease) - { - x = Event->xbutton.x; - y = Event->xbutton.y; - XMoveWindow(dpy,t->PagerView, x - (x1),y - (y1)); - finished = 1; + + if (moved) { + if ((x - xi < 3) && (y - yi < 3) && (x - xi > -3) && + (y - yi > -3)) + moved = 0; } - else if (Event->type == Expose) - { - HandleExpose(Event); + + if (KeepMoving) { + XTranslateCoordinates( + dpy, t->IconView, Scr.Root, x, y, &x1, &y1, &dumwin); + XUngrabPointer(dpy, CurrentTime); + XSync(dpy, 0); + snprintf(command, sizeof(command), "Move %dp %dp", x, y); + SendInfo(fd, command, t->w); + SendInfo(fd, "Raise", t->w); + SendInfo(fd, "Move", t->w); + } else { + x = x - x1; + y = y - y1; + n1 = x * (Scr.VxMax + Scr.MyDisplayWidth) / + (icon_w * Scr.MyDisplayWidth); + m1 = y * (Scr.VyMax + Scr.MyDisplayHeight) / + (icon_h * Scr.MyDisplayHeight); + x = (x - n1) * (Scr.VxMax + Scr.MyDisplayWidth) / (icon_w - n) - + Scr.Vx; + y = (y - m1) * (Scr.VyMax + Scr.MyDisplayHeight) / + (icon_h - m) - + Scr.Vy; + + if (((t->flags & ICONIFIED) && (t->flags & StickyIcon)) || + (t->flags & STICKY)) { + if (x > Scr.MyDisplayWidth - 16) + x = Scr.MyDisplayWidth - 16; + if (y > Scr.MyDisplayHeight - 16) + y = Scr.MyDisplayHeight - 16; + if (x + t->width < 16) + x = 16 - t->width; + if (y + t->height < 16) + y = 16 - t->height; + } + if (moved) { + if (t->flags & ICONIFIED) + XMoveWindow(dpy, t->icon_w, x, y); + else + XMoveWindow(dpy, t->w, x, y); + XSync(dpy, 0); + } else { + MoveResizePagerView(t); + } + SendInfo(fd, "Raise", t->w); + + if (t->flags & ICONIFIED) { + /* + RBW - reverting to old code for 2.2...temporarily. See + note above, in MoveWindow. + */ + XSetInputFocus(dpy, t->icon_w, RevertToParent, + Event->xbutton.time); + } else { + XSetInputFocus( + dpy, t->w, RevertToParent, Event->xbutton.time); + } } - } - - if(moved) - { - if((x - xi < 3)&&(y - yi < 3)&& - (x - xi > -3)&&(y -yi > -3)) - moved = 0; - } - - if(KeepMoving) - { - XTranslateCoordinates(dpy, t->IconView, Scr.Root, - x, y, &x1, &y1, &dumwin); - XUngrabPointer(dpy,CurrentTime); - XSync(dpy,0); - sprintf(command, "Move %dp %dp", x, y); - SendInfo(fd,command,t->w); - SendInfo(fd,"Raise",t->w); - SendInfo(fd,"Move",t->w); - } - else - { - x = x - x1; - y = y - y1; - n1 = x*(Scr.VxMax + Scr.MyDisplayWidth)/(icon_w * Scr.MyDisplayWidth); - m1 = y*(Scr.VyMax + Scr.MyDisplayHeight)/(icon_h * Scr.MyDisplayHeight); - x = (x-n1)* - (Scr.VxMax + Scr.MyDisplayWidth)/(icon_w-n) - Scr.Vx; - y = (y-m1)* - (Scr.VyMax + Scr.MyDisplayHeight)/(icon_h-m) - Scr.Vy; - - if(((t->flags & ICONIFIED)&&(t->flags & StickyIcon))|| - (t->flags & STICKY)) - { - if(x > Scr.MyDisplayWidth -16) - x = Scr.MyDisplayWidth - 16; - if(y > Scr.MyDisplayHeight-16) - y = Scr.MyDisplayHeight - 16; - if(x + t->width < 16) - x = 16 - t->width; - if(y + t->height < 16) - y = 16 - t->height; +} + +/* Just maps window ... draw stuff in it later after Expose event + -- ric@giccs.georgetown.edu */ +void +MapBalloonWindow(XEvent *event) +{ + PagerWindow *t; + XWindowChanges window_changes; + Window view, dummy; + int view_width, view_height; + int matched_window = 0; + int x, y; + extern char *BalloonBack; + + /* is this the best way to match X event window ID to PagerWindow ID? */ + t = Start; + + while (!matched_window) { + if (t == NULL) { + return; + } else if (t->PagerView == event->xcrossing.window) { + view = t->PagerView; + view_width = t->pager_view_width; + view_height = t->pager_view_height; + matched_window = 1; + } else if (t->IconView == event->xcrossing.window) { + view = t->IconView; + view_width = t->icon_view_width; + view_height = t->icon_view_height; + matched_window = 1; + } else { + t = t->next; + } } - if(moved) - { - if(t->flags & ICONIFIED) - XMoveWindow(dpy,t->icon_w,x,y); - else - XMoveWindow(dpy,t->w,x,y); - XSync(dpy,0); + + /* associate balloon with its pager window */ + balloon.pw = t; + + /* calculate window width to accommodate string */ + window_changes.width = + 4 + XTextWidth(balloon.font, t->icon_name, strlen(t->icon_name)); + + /* get x and y coords relative to pager window */ + x = (view_width / 2) - (window_changes.width / 2) - balloon.border; + + if (balloon.yoffset > 0) + y = view_height + balloon.yoffset; + else + y = balloon.yoffset - balloon.height - (2 * balloon.border); + + /* balloon is a top-level window, therefore need to + translate pager window coords to root window coords */ + XTranslateCoordinates(dpy, view, Scr.Root, x, y, &window_changes.x, + &window_changes.y, &dummy); + + /* make sure balloon doesn't go off screen + (actually 2 pixels from edge rather than 0 just to be pretty :-) */ + + /* too close to left */ + if (window_changes.x < 2) + window_changes.x = 2; + + /* too close to right */ + else if (window_changes.x + window_changes.width > + Scr.MyDisplayWidth - (2 * balloon.border) - 2) + window_changes.x = Scr.MyDisplayWidth - window_changes.width - + (2 * balloon.border) - 2; + + /* too close to top ... make yoffset +ve */ + if (window_changes.y < 2) { + y = -balloon.yoffset + view_height; + XTranslateCoordinates(dpy, view, Scr.Root, x, y, + &window_changes.x, &window_changes.y, &dummy); } - else - { - MoveResizePagerView(t); + + /* too close to bottom ... make yoffset -ve */ + else if (window_changes.y + balloon.height > + Scr.MyDisplayHeight - (2 * balloon.border) - 2) { + y = -balloon.yoffset - balloon.height - (2 * balloon.border); + XTranslateCoordinates(dpy, view, Scr.Root, x, y, + &window_changes.x, &window_changes.y, &dummy); } - SendInfo(fd,"Raise",t->w); - - if(t->flags & ICONIFIED) - { -/* - RBW - reverting to old code for 2.2...temporarily. See note above, in - MoveWindow. -*/ -#if 0 - SendInfo(fd, "Focus", t->icon_w); -#else - XSetInputFocus (dpy, t->icon_w, RevertToParent, Event->xbutton.time); -#endif - } - else - { -#if 0 - SendInfo(fd, "Focus", t->w); -#else - XSetInputFocus (dpy, t->w, RevertToParent, Event->xbutton.time); -#endif - } - } -} + /* make changes to window */ + XConfigureWindow(dpy, balloon.w, CWX | CWY | CWWidth, &window_changes); + /* if background not set in config make it match pager window */ + if (BalloonBack == NULL) + XSetWindowBackground(dpy, balloon.w, t->back); -/* Just maps window ... draw stuff in it later after Expose event - -- ric@giccs.georgetown.edu */ -void MapBalloonWindow (XEvent *event) -{ - PagerWindow *t; - XWindowChanges window_changes; - Window view, dummy; - int view_width, view_height; - int matched_window = 0; - int x, y; - extern char *BalloonBack; - - /* is this the best way to match X event window ID to PagerWindow ID? */ - t = Start; - - while ( ! matched_window ) { - if (t == NULL) { - return; - } - else if ( t->PagerView == event->xcrossing.window ) { - view = t->PagerView; - view_width = t->pager_view_width; - view_height = t->pager_view_height; - matched_window = 1; - } - else if ( t->IconView == event->xcrossing.window ) { - view = t->IconView; - view_width = t->icon_view_width; - view_height = t->icon_view_height; - matched_window = 1; - } - else { - t = t->next; - } - } - - /* associate balloon with its pager window */ - balloon.pw = t; - - /* calculate window width to accommodate string */ - window_changes.width = 4 + XTextWidth(balloon.font, t->icon_name, - strlen(t->icon_name)); - - /* get x and y coords relative to pager window */ - x = (view_width / 2) - (window_changes.width / 2) - balloon.border; - - if ( balloon.yoffset > 0 ) - y = view_height + balloon.yoffset; - else - y = balloon.yoffset - balloon.height - (2 * balloon.border); - - - /* balloon is a top-level window, therefore need to - translate pager window coords to root window coords */ - XTranslateCoordinates(dpy, view, Scr.Root, x, y, - &window_changes.x, &window_changes.y, &dummy); - - - /* make sure balloon doesn't go off screen - (actually 2 pixels from edge rather than 0 just to be pretty :-) */ - - /* too close to left */ - if ( window_changes.x < 2 ) - window_changes.x = 2; - - /* too close to right */ - else if ( window_changes.x + window_changes.width > - Scr.MyDisplayWidth - (2 * balloon.border) - 2 ) - window_changes.x = Scr.MyDisplayWidth - window_changes.width - - (2 * balloon.border) - 2; - - /* too close to top ... make yoffset +ve */ - if ( window_changes.y < 2 ) { - y = - balloon.yoffset + view_height; - XTranslateCoordinates(dpy, view, Scr.Root, x, y, - &window_changes.x, &window_changes.y, &dummy); - } - - /* too close to bottom ... make yoffset -ve */ - else if ( window_changes.y + balloon.height > - Scr.MyDisplayHeight - (2 * balloon.border) - 2 ) { - y = - balloon.yoffset - balloon.height - (2 * balloon.border); - XTranslateCoordinates(dpy, view, Scr.Root, x, y, - &window_changes.x, &window_changes.y, &dummy); - } - - - /* make changes to window */ - XConfigureWindow(dpy, balloon.w, CWX | CWY | CWWidth, &window_changes); - - /* if background not set in config make it match pager window */ - if ( BalloonBack == NULL ) - XSetWindowBackground(dpy, balloon.w, t->back); - - XMapRaised(dpy, balloon.w); + XMapRaised(dpy, balloon.w); } - /* -- ric@giccs.georgetown.edu */ -void UnmapBalloonWindow (void) +void +UnmapBalloonWindow(void) { - XUnmapWindow(dpy, balloon.w); + XUnmapWindow(dpy, balloon.w); } - /* Draws string in balloon window -- call after it's received Expose event -- ric@giccs.georgetown.edu */ -void DrawInBalloonWindow (void) +void +DrawInBalloonWindow(void) { - extern char *BalloonFore; + extern char *BalloonFore; - /* if foreground not set in config make it match pager window */ - if ( BalloonFore == NULL ) - XSetForeground(dpy, BalloonGC, balloon.pw->text); + /* if foreground not set in config make it match pager window */ + if (BalloonFore == NULL) + XSetForeground(dpy, BalloonGC, balloon.pw->text); - XDrawString(dpy, balloon.w, BalloonGC, - 2, balloon.font->ascent, - balloon.pw->icon_name, strlen(balloon.pw->icon_name)); + XDrawString(dpy, balloon.w, BalloonGC, 2, balloon.font->ascent, + balloon.pw->icon_name, strlen(balloon.pw->icon_name)); } Index: fvwm/modules/FvwmSave/FvwmSave.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSave/FvwmSave.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSave/FvwmSave.1 --- fvwm/modules/FvwmSave/FvwmSave.1 +++ fvwm/modules/FvwmSave/FvwmSave.1 @@ -1,65 +1,59 @@ .\" $OpenBSD: FvwmSave.1,v 1.1.1.1 2006/11/26 10:53:53 matthieu Exp $ .\" t .\" @(#)FvwmSave.1 1/28/94 -.TH FvwmSave 1 "Jan 28 1994" 1.20 +.TH FVWMSAVE 1 "January 28, 1994" "1.20" "FVWM Modules" .UC .SH NAME FvwmSave \- the FVWM desktop-layout saving module .SH SYNOPSIS FvwmSave is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -When called, this module will attempt to save your current desktop -layout into a file called new.xinitrc. Ideally, this file will look just -like .xinitrc, but in reality, you will have to edit it to get a -useable configuration, so be sure to keep a backup of your old .xinitrc. - -Your applications must supply certain hints to the X window system. -Emacs, for example, does not, so FvwmSave can't get any -information from it. - -Also, FvwmSave assumes that certain command line options are -globally accepted by applications, which may not be the case. - +When called, this module attempts to save your current desktop layout into a +file called new.xinitrc. Ideally, this file will look just like .xinitrc, but +in practice you will have to edit it to get a usable configuration, so keep a +backup of your existing .xinitrc. +.PP +Applications must supply certain hints to the X Window System. Emacs, for +example, does not, so FvwmSave cannot obtain any information from it. +.PP +FvwmSave also assumes that certain command line options are globally accepted +by applications, which may not be the case. .SH COPYRIGHTS -The NoClutter program, and the concept for -interfacing this module to the Window Manager, are all original work -by Robert Nation - -Copyright 1994, Robert Nation. No guarantees or warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - - +The NoClutter program, and the concept for interfacing this module to the +window manager, are all original work by Robert Nation. +.PP +Copyright 1994, Robert Nation. No guarantees or warranties or anything are +provided or implied in any way whatsoever. Use this program at your own risk. +Permission to use this program for any purpose is given, as long as the +copyright is kept intact. .SH INITIALIZATION -During initialization, \fINoClutter\fP will eventually search a -configuration file which describes the time-outs and actions to take. -The configuration file is the same file that fvwm used during initialization. - -If the NoClutter executable is linked to another name, ie ln -s -NoClutter OtherClutter, then another module called OtherClutter can be -started, with a completely different configuration than NoClutter, -simply by changing the keyword NoClutter to OtherClutter. This way multiple -clutter-reduction programs can be used. - +During initialization, \fINoClutter\fP searches a configuration file that +describes the time-outs and actions to take. The configuration file is the same +one that fvwm reads during its own initialization. +.PP +If the NoClutter executable is linked to another name, for example `ln -s +NoClutter OtherClutter`, then another module called OtherClutter can be +started with a completely different configuration. This is achieved by changing +the keyword NoClutter to OtherClutter so multiple clutter-reduction programs +can be used. +.PP +FvwmSave follows the same configuration pattern. .SH INVOCATION -NoClutter can be invoked by inserting the line 'Module NoClutter' in -the .fvwmrc file. This can be placed on a line by itself, if NoClutter -is to be spawned during fvwm's initialization, or can be bound to a -menu or mouse button or keystroke to invoke it later. Fvwm will search -directory specified in the ModulePath configuration option to attempt -to locate NoClutter. - +NoClutter can be invoked by inserting the line `Module NoClutter` in the +\&.fvwmrc file. This can be placed on a line by itself if NoClutter is to be +spawned during fvwm's initialization, or it can be bound to a menu, mouse +button, or keystroke to invoke it later. Fvwm searches the directory specified +in the ModulePath configuration option to locate NoClutter. +.PP +FvwmSave is launched by fvwm in the same fashion. .SH CONFIGURATION OPTIONS -NoClutter reads the same .fvwmrc file as fvwm reads when it starts up, -and looks for lines similar to "*NoClutter 3600 Iconify". The format -of these lines is "*NoClutter [time] [command]", where command is any -fvwm built-in command, and time is the time in seconds between when a -window looses focus and when the command is executed. At most 3 -actions can be specified. - - +NoClutter reads the same .fvwmrc file as fvwm reads when it starts up and looks +for lines similar to "*NoClutter 3600 Iconify". The format of these lines is +"*NoClutter [time] [command]", where command is any fvwm built-in command, and +time is the interval in seconds between when a window loses focus and when the +command is executed. At most three actions can be specified. +.PP +FvwmSave recognises the analogous "*FvwmSave" syntax. .SH AUTHOR Robert Nation and Mr. Per Persson (Omnion on IRC) Index: fvwm/modules/FvwmSave/FvwmSave.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSave/FvwmSave.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSave/FvwmSave.c --- fvwm/modules/FvwmSave/FvwmSave.c +++ fvwm/modules/FvwmSave/FvwmSave.c @@ -3,38 +3,39 @@ * by Robert Nation and Mr. Per Persson * * Copyright 1994, Robert Nation and Mr. Per Persson. - * No guarantees or warantees or anything + * No guarantees or warantees or anything * are provided or implied in any way whatsoever. Use this program at your * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ -#include "config.h" +#include "FvwmSave.h" -#include -#include -#include -#include -#include #include -#include -#include -#include +#include + +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include "../../fvwm/module.h" - -#include "FvwmSave.h" +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" char *MyName; int fd[2]; struct list *list_root = NULL; -Display *dpy; /* which display are we talking to */ +Display *dpy; /* which display are we talking to */ int ScreenWidth, ScreenHeight; int screen; @@ -46,55 +47,55 @@ long Vx, Vy; * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - char *display_name = NULL; - - /* Record the program name for error messages */ - temp = argv[0]; - - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - - if((argc != 6)&&(argc != 7)) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - /* Open the X display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - screen= DefaultScreen(dpy); - ScreenHeight = DisplayHeight(dpy,screen); - ScreenWidth = DisplayWidth(dpy,screen); - - /* We should exit if our fvwm pipes die */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - /* Create a list of all windows */ - /* Request a list of all windows, - * wait for ConfigureWindow packets */ - SendInfo(fd,"Send_WindowList",0); - - Loop(fd); - return 0; -} + char *temp, *s; + char *display_name = NULL; + + /* Record the program name for error messages */ + temp = argv[0]; + + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + size_t name_len = strlen(temp); + MyName = xmalloc(name_len + 2); + strlcpy(MyName, "*", name_len + 2); + strlcat(MyName, temp, name_len + 2); + + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); + } + + /* Open the X display */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + screen = DefaultScreen(dpy); + ScreenHeight = DisplayHeight(dpy, screen); + ScreenWidth = DisplayWidth(dpy, screen); + /* We should exit if our fvwm pipes die */ + signal(SIGPIPE, DeadPipe); + + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + /* Create a list of all windows */ + /* Request a list of all windows, + * wait for ConfigureWindow packets */ + SendInfo(fd, "Send_WindowList", 0); + + Loop(fd); + return 0; +} /*********************************************************************** * @@ -102,132 +103,129 @@ int main(int argc, char **argv) * Loop - wait for data to process * ***********************************************************************/ -void Loop(int *fd) +void +Loop(int *fd) { - unsigned long header[HEADER_SIZE], *body; - int count; - - while(1) - { - /* read a packet */ - if((count = ReadFvwmPacket(fd[1],header, &body)) > 0) - { - /* dispense with the new packet */ - process_message(header[1],body); - free(body); + unsigned long header[HEADER_SIZE], *body; + int count; + + unveil_home_write("FvwmSave"); + unveil(NULL, NULL); + sandbox_save_state("FvwmSave"); + + while (1) { + /* read a packet */ + if ((count = ReadFvwmPacket(fd[1], header, &body)) > 0) { + /* dispense with the new packet */ + process_message(header[1], body); + free(body); + } } - } } - /*********************************************************************** * * Procedure: * Process message - examines packet types, and takes appropriate action * ***********************************************************************/ -void process_message(unsigned long type,unsigned long *body) +void +process_message(unsigned long type, unsigned long *body) { - switch(type) - { - case M_CONFIGURE_WINDOW: - if(!find_window(body[0])) - add_window(body[0],body); - break; - case M_NEW_PAGE: - list_new_page(body); - break; - case M_END_WINDOWLIST: - do_save(); - break; - default: - break; - } + switch (type) { + case M_CONFIGURE_WINDOW: + if (!find_window(body[0])) + add_window(body[0], body); + break; + case M_NEW_PAGE: + list_new_page(body); + break; + case M_END_WINDOWLIST: + do_save(); + break; + default: + break; + } } - - - - /*********************************************************************** * * Procedure: * find_window - find a window in the current window list * ***********************************************************************/ -struct list *find_window(unsigned long id) +struct list * +find_window(unsigned long id) { - struct list *l; + struct list *l; - if(list_root == NULL) - return NULL; + if (list_root == NULL) + return NULL; - for(l = list_root; l!= NULL; l= l->next) - { - if(l->id == id) - return l; - } - return NULL; + for (l = list_root; l != NULL; l = l->next) { + if (l->id == id) + return l; + } + return NULL; } - - /*********************************************************************** * * Procedure: * add_window - add a new window in the current window list * ***********************************************************************/ -void add_window(unsigned long new_win, unsigned long *body) +void +add_window(unsigned long new_win, unsigned long *body) { - struct list *t; - - if(new_win == 0) - return; - - t = (struct list *)safemalloc(sizeof(struct list)); - t->id = new_win; - t->next = list_root; - t->frame_height = (int)body[6]; - t->frame_width = (int)body[5]; - t->base_width = (int)body[11]; - t->base_height = (int)body[12]; - t->width_inc = (int)body[13]; - t->height_inc = (int)body[14]; - t->frame_x = (int)body[3]; - t->frame_y = (int)body[4];; - t->title_height = (int)body[9];; - t->boundary_width = (int)body[10]; - t->flags = (unsigned long)body[8]; - t->gravity = body[21]; - list_root = t; + struct list *t; + + if (new_win == 0) + return; + + t = (struct list *)xmalloc(sizeof(struct list)); + t->id = new_win; + t->next = list_root; + t->frame_height = (int)body[6]; + t->frame_width = (int)body[5]; + t->base_width = (int)body[11]; + t->base_height = (int)body[12]; + t->width_inc = (int)body[13]; + t->height_inc = (int)body[14]; + t->frame_x = (int)body[3]; + t->frame_y = (int)body[4]; + t->title_height = (int)body[9]; + t->boundary_width = (int)body[10]; + t->flags = (unsigned long)body[8]; + t->gravity = body[21]; + list_root = t; } - - /*********************************************************************** * * Procedure: * list_new_page - capture new-page info * ***********************************************************************/ -void list_new_page(unsigned long *body) +void +list_new_page(unsigned long *body) { - Vx = (long)body[0]; - Vy = (long)body[1]; + Vx = (long)body[0]; + Vy = (long)body[1]; } + /*********************************************************************** * * Procedure: * SIGPIPE handler - SIGPIPE means fvwm is dying * ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(0); + exit(0); } - /*********************************************************************** * * Procedure: @@ -235,40 +233,35 @@ void DeadPipe(int nonsense) * checks for qoutes and stuff * ***********************************************************************/ -void write_string(FILE *out, char *line) +void +write_string(FILE *out, char *line) { - int len,space = 0, qoute = 0,i; - - len = strlen(line); - - for(i=0;inext) - { - tname[0]=0; - - x1 = t->frame_x; - x2 = ScreenWidth - x1 - t->frame_width - 2; - if(x2 < 0) - x2 = 0; - y1 = t->frame_y; - y2 = ScreenHeight - y1 - t->frame_height - 2; - if(y2 < 0) - y2 = 0; - dheight = t->frame_height - t->title_height - 2*t->boundary_width; - dwidth = t->frame_width - 2*t->boundary_width; - dwidth -= t->base_width ; - dheight -= t->base_height ; - dwidth /= t->width_inc; - dheight /= t->height_inc; - - if ( t->flags & STICKY ) - { - tVx = 0; - tVy = 0; - } - else - { - tVx = Vx; - tVy = Vy; + struct list *t; + char tname[200], loc[30]; + FILE *out; + char **command_list; + int dwidth, dheight, xtermline = 0; + int x1, x2, y1, y2, i, command_count; + long tVx, tVy; + + snprintf(tname, sizeof(tname), "%s/new.xinitrc", + getenv("HOME") ? getenv("HOME") : "."); + out = fopen(tname, "w+"); + if (out == NULL) { + fprintf(stderr, "%s: couldn't open %s for writing\n", + Myname, tname); + return; } - sprintf(tname,"%dx%d",dwidth,dheight); - if ((t->gravity == EastGravity) || - (t->gravity == NorthEastGravity) || - (t->gravity == SouthEastGravity)) - sprintf(loc,"-%d",x2); - else - sprintf(loc,"+%d",x1+(int)tVx); - strcat(tname, loc); - - if((t->gravity == SouthGravity)|| - (t->gravity == SouthEastGravity)|| - (t->gravity == SouthWestGravity)) - sprintf(loc,"-%d",y2); - else - sprintf(loc,"+%d",y1+(int)tVy); - strcat(tname, loc); - - if ( XGetCommand( dpy, t->id, &command_list, &command_count ) ) - { - for (i=0; i < command_count; i++) - { - if ( strncmp( "-geo", command_list[i], 4) == 0) - { - i++; - continue; - } - if ( strncmp( "-ic", command_list[i], 3) == 0) - continue; - if ( strncmp( "-display", command_list[i], 8) == 0) - { - i++; - continue; - } - write_string(out,command_list[i]); - if(strstr(command_list[i], "xterm")) - { - fprintf( out, "-geometry %s ", tname ); - if ( t->flags & ICONIFIED ) - fprintf(out, "-ic "); - xtermline = 1; + for (t = list_root; t != NULL; t = t->next) { + tname[0] = 0; + + x1 = t->frame_x; + x2 = ScreenWidth - x1 - t->frame_width - 2; + if (x2 < 0) + x2 = 0; + y1 = t->frame_y; + y2 = ScreenHeight - y1 - t->frame_height - 2; + if (y2 < 0) + y2 = 0; + dheight = + t->frame_height - t->title_height - 2 * t->boundary_width; + dwidth = t->frame_width - 2 * t->boundary_width; + dwidth -= t->base_width; + dheight -= t->base_height; + if (t->width_inc != 0) + dwidth /= t->width_inc; + if (t->height_inc != 0) + dheight /= t->height_inc; + + if (t->flags & STICKY) { + tVx = 0; + tVy = 0; + } else { + tVx = Vx; + tVy = Vy; } - } - if ( command_count > 0 ) - { - if ( xtermline == 0 ) - { - if ( t->flags & ICONIFIED ) - fprintf(out, "-ic "); - fprintf( out, "-geometry %s &\n", tname ); + snprintf(tname, sizeof(tname), "%dx%d", dwidth, dheight); + if ((t->gravity == EastGravity) || + (t->gravity == NorthEastGravity) || + (t->gravity == SouthEastGravity)) + snprintf(loc, sizeof(loc), "-%d", x2); + else + snprintf(loc, sizeof(loc), "+%d", x1 + (int)tVx); + strlcat(tname, loc, sizeof(tname)); + + if ((t->gravity == SouthGravity) || + (t->gravity == SouthEastGravity) || + (t->gravity == SouthWestGravity)) + snprintf(loc, sizeof(loc), "-%d", y2); + else + snprintf(loc, sizeof(loc), "+%d", y1 + (int)tVy); + strlcat(tname, loc, sizeof(tname)); + + if (XGetCommand(dpy, t->id, &command_list, &command_count)) { + for (i = 0; i < command_count; i++) { + if (strncmp("-geo", command_list[i], 4) == 0) { + i++; + continue; + } + if (strncmp("-ic", command_list[i], 3) == 0) + continue; + if (strncmp("-display", command_list[i], 8) == + 0) { + i++; + continue; + } + write_string(out, command_list[i]); + if (strstr(command_list[i], "xterm")) { + fprintf(out, "-geometry %s ", tname); + if (t->flags & ICONIFIED) + fprintf(out, "-ic "); + xtermline = 1; + } + } + if (command_count > 0) { + if (xtermline == 0) { + if (t->flags & ICONIFIED) + fprintf(out, "-ic "); + fprintf(out, "-geometry %s &\n", tname); + } else { + fprintf(out, "&\n"); + } + } + XFreeStringList(command_list); + xtermline = 0; } - else - { - fprintf( out, "&\n"); - } - } - XFreeStringList( command_list ); - xtermline = 0; } - } - fprintf(out, "fvwm\n"); - fclose( out ); - exit(0); - + fprintf(out, "fvwm\n"); + fclose(out); + exit(0); } - Index: fvwm/modules/FvwmSave/FvwmSave.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSave/FvwmSave.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSave/FvwmSave.h --- fvwm/modules/FvwmSave/FvwmSave.h +++ fvwm/modules/FvwmSave/FvwmSave.h @@ -1,38 +1,35 @@ -#include "fvwmlib.h" +#include "fvwmlib.h" #define STICKY 1 -#define ICONIFIED 32 /* is it an icon now? */ +#define ICONIFIED 32 /* is it an icon now? */ -struct list -{ - unsigned long id; - int frame_height; - int frame_width; - int base_width; - int base_height; - int width_inc; - int height_inc; - int frame_x; - int frame_y; - int title_height; - int boundary_width; - unsigned long flags; - unsigned long gravity; - struct list *next; +struct list { + unsigned long id; + int frame_height; + int frame_width; + int base_width; + int base_height; + int width_inc; + int height_inc; + int frame_x; + int frame_y; + int title_height; + int boundary_width; + unsigned long flags; + unsigned long gravity; + struct list *next; }; /************************************************************************* * * Subroutine Prototypes - * + * *************************************************************************/ void Loop(int *fd); -void SendInfo(int *fd,char *message,unsigned long window); -char *safemalloc(int length); +void SendInfo(int *fd, char *message, unsigned long window); struct list *find_window(unsigned long id); void add_window(unsigned long new_win, unsigned long *body); void DeadPipe(int nonsense); -void process_message(unsigned long type,unsigned long *body); +void process_message(unsigned long type, unsigned long *body); void do_save(void); void list_new_page(unsigned long *body); - Index: fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.1 --- fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.1 +++ fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.1 @@ -1,93 +1,86 @@ .\" $OpenBSD: FvwmSaveDesk.1,v 1.2 2007/04/16 16:32:01 jmc Exp $ .\" t -.\" @(#)FvwmSaveDesk.1 6/6/96 -.TH FvwmSaveDesk 1 "Jul 6 1996" 2.0 +.\" @(#)FvwmSaveDesk.1 6/6/96 +.TH FVWMSAVEDESK 1 "July 6, 1996" "2.0" "FVWM Modules" .UC .SH NAME FvwmSaveDesk \- another FVWM desktop-layout saving module .SH SYNOPSIS FvwmSaveDesk is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -When called, this module will attempt to save your current desktop -layout as a definition of extra lines for the function InitFunction -into the file -.I .fvwm2desk -in your home directory. As explain in the other documation, this -function is called at startup of fvwm2. -You have to include this file in -.I .fvwmrc -after the definition of the Function Initfunction. -You can do this by using the module -.I FvwmM4 -or -.I FvwmCpp. - -Your applications must supply certain hints to the X window system. -.I Emacs -and -.I Netscape -, for example, does not, so FvwmSaveDesk can't get any -information from it. - -Also, FvwmSaveDesk assumes that certain command line options are -globally accepted by applications, which may not be the case. - +FvwmSaveDesk saves the current desktop layout as additional lines for the +function InitFunction in the file \fI.fvwm2desk\fP that is created in the +user's home directory. As explained in the other documentation, InitFunction +is executed when fvwm starts. The generated file must therefore be included in +\fI.fvwmrc\fP after the definition of InitFunction. Modules such as FvwmM4 or +FvwmCpp can insert the file automatically. +.PP +Client applications must supply the usual hints to the X Window System. +Programs like Emacs and Netscape do not, so FvwmSaveDesk cannot extract any +information from them. +.PP +FvwmSaveDesk also assumes that certain command line options are accepted by +applications, which may not always be true. .SH SETUP USING FVWMM4 MODULE -The M4 Macro processor substitutes its macros even in the middle of a -word. Because of that you may have problems with predefined macros -such as include or define. To avoid this the GNU M4 has an extra -option to prefix all builtins with 'm4_'. FvwmM4 can be called with -option -m4-prefix and then will provide the option -P to M4. -I personally use the FvwmM4 module this way. - +The M4 macro processor substitutes its macros even in the middle of a word. +Because of that you may have problems with predefined macros such as +`include` or `define`. To avoid this, GNU M4 provides an option to prefix all +built-ins with `m4_`. FvwmM4 accepts the option \-m4-prefix and then passes +\-P to M4. A typical invocation looks like this: +.PP +.EX fvwm2 -f "FvwmM4 -m4-prefix -m4opt -I$HOME $HOME/.fvwmrc" - -Simply add the following line to the end of .fvwmrc: - -m4_include(`.fvwm2desk') . - +.EE +.PP +Add the following line to the end of \fI.fvwmrc\fP: +.PP +.EX +m4_include(`.fvwm2desk') +.EE .SH SETUP USING FVWMCPP MODULE -With the FVWMCPP you may have the problem that the preprocessor -directives starts with the comment charakter '#' and will -complain about unknown directives, if you have comments in your .fvwmrc. - -fvwm2 -f "FvwmCpp -C-I$HOME $HOME/.fvwmrc" - -Simply add the following line to the end of .fvwmrc: - +With FVWMCPP you may encounter problems because preprocessor directives start +with the comment character `#` and may be treated as comments. If this happens +you can invoke fvwm like this: +.PP +.EX +fvwm2 -f "FvwmCpp -C -I$HOME $HOME/.fvwmrc" +.EE +.PP +Then append the following line to the end of \fI.fvwmrc\fP: +.PP +.EX #include ".fvwm2desk" - +.EE .SH INVOCATION -FvwmSaveDesk can be invoked by adding it to a menu or binding it to a -mouse button or keystoke in -the -.I .fvwmrc -file. -Fvwm2 will search directory specified in the ModulePath -configuration option to locate FvwmSaveDesk. - -To insert it to a menu, add the line - -+ "Save Desktop" Module FvwmSaveDesk - -to the menu definition. -I thing binding it to a mouse button is not very useful, but you can -do that, by adding for example this line. - -Mouse 3 R CS Module FvwmSaveDesk - -Than FvwmSaveDesk will be called if you hit the right mouse button -on the root window while holding the shift and control button down. - -You can bind FvwmSaveDesk to a function key F10 for example you have -to insert the following line: - -Key F10 A Module FvwmSaveDesk - -I personally add it as a Button to the module FvwmButtons: - -*FvwmButtons SaveDesc desk.xpm Module FvwmSaveDesk - +FvwmSaveDesk can be invoked by adding it to a menu or by binding it to a mouse +button or keystroke in the \fI.fvwmrc\fP file. Fvwm searches the directory +listed in the ModulePath configuration option to locate FvwmSaveDesk. +.PP +To insert it into a menu, add the line: +.PP +.EX ++ "Save Desktop" Module FvwmSaveDesk +.EE +.PP +Binding the module to a mouse button is less common, but can be done with: +.PP +.EX +Mouse 3 R CS Module FvwmSaveDesk +.EE +.PP +This calls FvwmSaveDesk when you press the right mouse button on the root +window while holding Shift and Control. +.PP +To bind the module to the function key F10, add: +.PP +.EX +Key F10 A Module FvwmSaveDesk +.EE +.PP +You can also place it on a FvwmButtons panel: +.PP +.EX +*FvwmButtons SaveDesc desk.xpm Module FvwmSaveDesk +.EE .SH AUTHOR Carsten Paeth (calle@calle.in-berlin.de) Index: fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c --- fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c +++ fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c @@ -6,13 +6,13 @@ * is from Carsten Paeth * * Copyright 1994, Robert Nation and Mr. Per Persson. - * No guarantees or warantees or anything + * No guarantees or warantees or anything * are provided or implied in any way whatsoever. Use this program at your * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. * * Copyright 1995, Carsten Paeth. - * No guarantees or warantees or anything + * No guarantees or warantees or anything * are provided or implied in any way whatsoever. Use this program at your * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. @@ -22,39 +22,40 @@ #define TRUE 1 #define FALSE 0 -#include "config.h" +#include "FvwmSaveDesk.h" -#include -#include -#include -#include -#include #include -#include -#include -#include +#include + +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include "../../fvwm/module.h" - -#include "FvwmSaveDesk.h" +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" char *MyName; int fd[2]; struct list *list_root = NULL; -Display *dpy; /* which display are we talking to */ +Display *dpy; /* which display are we talking to */ int ScreenWidth, ScreenHeight; int screen; long Vx, Vy; -long CurDesk = 1; /* actual Desktop while being called */ +long CurDesk = 1; /* actual Desktop while being called */ /*********************************************************************** * @@ -62,56 +63,55 @@ long CurDesk = 1; /* actual Desktop while being called */ * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - char *display_name = NULL; - - /* Record the program name for error messages */ - temp = argv[0]; - - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - - if((argc != 6)&&(argc != 7)) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - /* Open the X display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - screen= DefaultScreen(dpy); - ScreenHeight = DisplayHeight(dpy,screen); - ScreenWidth = DisplayWidth(dpy,screen); - - /* We should exit if our fvwm pipes die */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - /* Create a list of all windows */ - /* Request a list of all windows, - * wait for ConfigureWindow packets */ - SendInfo(fd,"Send_WindowList",0); - - Loop(fd); - return 0; -} + char *temp, *s; + char *display_name = NULL; + + /* Record the program name for error messages */ + temp = argv[0]; + + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + size_t name_len = strlen(temp); + MyName = xmalloc(name_len + 2); + strlcpy(MyName, "*", name_len + 2); + strlcat(MyName, temp, name_len + 2); + + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); + } + /* Open the X display */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + screen = DefaultScreen(dpy); + ScreenHeight = DisplayHeight(dpy, screen); + ScreenWidth = DisplayWidth(dpy, screen); + /* We should exit if our fvwm pipes die */ + signal(SIGPIPE, DeadPipe); + + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + /* Create a list of all windows */ + /* Request a list of all windows, + * wait for ConfigureWindow packets */ + SendInfo(fd, "Send_WindowList", 0); + + Loop(fd); + return 0; +} /*********************************************************************** * @@ -119,144 +119,144 @@ int main(int argc, char **argv) * Loop - wait for data to process * ***********************************************************************/ -void Loop(int *fd) +void +Loop(int *fd) { - unsigned long header[HEADER_SIZE], *body; - int count; - - while(1) - { - /* read a packet */ - if((count = ReadFvwmPacket(fd[1],header,&body)) > 0) - { - /* dispense with the new packet */ - process_message(header[1],body); - free(body); + unsigned long header[HEADER_SIZE], *body; + int count; + + unveil_home_write("FvwmSaveDesk"); + unveil(NULL, NULL); + sandbox_save_state("FvwmSaveDesk"); + + while (1) { + /* read a packet */ + if ((count = ReadFvwmPacket(fd[1], header, &body)) > 0) { + /* dispense with the new packet */ + process_message(header[1], body); + free(body); + } } - } } - /*********************************************************************** * * Procedure: * Process message - examines packet types, and takes appropriate action * ***********************************************************************/ -void process_message(unsigned long type,unsigned long *body) +void +process_message(unsigned long type, unsigned long *body) { - switch(type) - { - case M_CONFIGURE_WINDOW: - if(!find_window(body[0])) - add_window(body[0],body); - break; - case M_WINDOW_NAME: - { - struct list *l; - if ((l = find_window(body[0])) != 0) { - l->name = (char *)safemalloc(strlen((char *)&body[3])+1); - strcpy(l->name,(char *)&body[3]); + switch (type) { + case M_CONFIGURE_WINDOW: + if (!find_window(body[0])) + add_window(body[0], body); + break; + case M_WINDOW_NAME: { + struct list *l; + if ((l = find_window(body[0])) != 0) { + size_t name_len = strlen((char *)&body[3]); + free(l->name); + l->name = (char *)xmalloc(name_len + 1); + strlcpy(l->name, (char *)&body[3], name_len + 1); + } + } + break; + case M_NEW_PAGE: + list_new_page(body); + break; + case M_NEW_DESK: + CurDesk = (long)body[0]; + break; + case M_END_WINDOWLIST: + do_save(); + break; + default: + break; } - } - break; - case M_NEW_PAGE: - list_new_page(body); - break; - case M_NEW_DESK: - CurDesk = (long)body[0]; - break; - case M_END_WINDOWLIST: - do_save(); - break; - default: - break; - } } - - /*********************************************************************** * * Procedure: * find_window - find a window in the current window list * ***********************************************************************/ -struct list *find_window(unsigned long id) +struct list * +find_window(unsigned long id) { - struct list *l; + struct list *l; - if(list_root == NULL) - return NULL; + if (list_root == NULL) + return NULL; - for(l = list_root; l!= NULL; l= l->next) - { - if(l->id == id) - return l; - } - return NULL; + for (l = list_root; l != NULL; l = l->next) { + if (l->id == id) + return l; + } + return NULL; } - - /*********************************************************************** * * Procedure: * add_window - add a new window in the current window list * ***********************************************************************/ -void add_window(unsigned long new_win, unsigned long *body) +void +add_window(unsigned long new_win, unsigned long *body) { - struct list *t; - - if(new_win == 0) - return; - - t = (struct list *)safemalloc(sizeof(struct list)); - t->id = new_win; - t->next = list_root; - t->frame_height = (int)body[6]; - t->frame_width = (int)body[5]; - t->base_width = (int)body[11]; - t->base_height = (int)body[12]; - t->width_inc = (int)body[13]; - t->height_inc = (int)body[14]; - t->frame_x = (int)body[3]; - t->frame_y = (int)body[4];; - t->title_height = (int)body[9];; - t->boundary_width = (int)body[10]; - t->flags = (unsigned long)body[8]; - t->gravity = body[21]; - t->desk = body[7]; - t->name = 0; - list_root = t; + struct list *t; + + if (new_win == 0) + return; + + t = (struct list *)xmalloc(sizeof(struct list)); + t->id = new_win; + t->next = list_root; + t->frame_height = (int)body[6]; + t->frame_width = (int)body[5]; + t->base_width = (int)body[11]; + t->base_height = (int)body[12]; + t->width_inc = (int)body[13]; + t->height_inc = (int)body[14]; + t->frame_x = (int)body[3]; + t->frame_y = (int)body[4]; + t->title_height = (int)body[9]; + t->boundary_width = (int)body[10]; + t->flags = (unsigned long)body[8]; + t->gravity = body[21]; + t->desk = body[7]; + t->name = 0; + list_root = t; } - - /*********************************************************************** * * Procedure: * list_new_page - capture new-page info * ***********************************************************************/ -void list_new_page(unsigned long *body) +void +list_new_page(unsigned long *body) { - Vx = (long)body[0]; - Vy = (long)body[1]; + Vx = (long)body[0]; + Vy = (long)body[1]; } + /*********************************************************************** * * Procedure: * SIGPIPE handler - SIGPIPE means fvwm is dying * ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(0); + exit(0); } - /*********************************************************************** * * Procedure: @@ -264,155 +264,144 @@ void DeadPipe(int nonsense) * checks for qoutes and stuff * ***********************************************************************/ -void write_string(FILE *out, char *line) +void +write_string(FILE *out, char *line) { - int len,space = 0, qoute = 0,i; - - len = strlen(line); - - for(i=0;iframe_x; - x2 = ScreenWidth - x1 - t->frame_width - 2; - if(x2 < 0) - x2 = 0; - y1 = t->frame_y; - y2 = ScreenHeight - y1 - t->frame_height - 2; - if(y2 < 0) - y2 = 0; - dheight = t->frame_height - t->title_height - 2*t->boundary_width; - dwidth = t->frame_width - 2*t->boundary_width; - dwidth -= t->base_width ; - dheight -= t->base_height ; - dwidth /= t->width_inc; - dheight /= t->height_inc; - - if ( t->flags & STICKY ) - { - tVx = 0; - tVy = 0; - } - else - { - tVx = Vx; - tVy = Vy; - } - sprintf(tname,"%dx%d",dwidth,dheight); - if ((t->gravity == EastGravity) || - (t->gravity == NorthEastGravity) || - (t->gravity == SouthEastGravity)) - sprintf(loc,"-%d",x2); - else - sprintf(loc,"+%d",x1+(int)tVx); - strcat(tname, loc); - - if((t->gravity == SouthGravity)|| - (t->gravity == SouthEastGravity)|| - (t->gravity == SouthWestGravity)) - sprintf(loc,"-%d",y2); - else - sprintf(loc,"+%d",y1+(int)tVy); - strcat(tname, loc); - - if ( XGetCommand( dpy, t->id, &command_list, &command_count ) ) - { - if (*curdesk != t->desk) - { - fprintf( out, "%s\t\"I\" Desk 0 %ld\n", *isfirstline ? "" : "+", t->desk); - fflush ( out ); - if (*isfirstline) *isfirstline = 0; - *curdesk = t->desk; - } - - fprintf( out, "%s\t\t\"I\" Exec ", *isfirstline ? "" : "+"); - if (*isfirstline) *isfirstline = 0; - fflush ( out ); - for (i=0; i < command_count; i++) - { - if ( strncmp( "-geo", command_list[i], 4) == 0) - { - i++; - continue; - } - if ( strncmp( "-ic", command_list[i], 3) == 0) - continue; - if ( strncmp( "-display", command_list[i], 8) == 0) - { - i++; - continue; - } - write_string(out,command_list[i]); - fflush ( out ); - if(strstr(command_list[i], "xterm")) - { - fprintf( out, "-geometry %s ", tname ); - if ( t->flags & ICONIFIED ) - fprintf(out, "-ic "); - xtermline = 1; - fflush ( out ); - } - } - if ( command_count > 0 ) - { - if ( xtermline == 0 ) - { - if ( t->flags & ICONIFIED ) - fprintf(out, "-ic "); - fprintf( out, "-geometry %s &\n", tname); - } - else - { - fprintf( out, "&\n"); - } - } - if (emit_wait) { - if (t->name) - fprintf( out, "+\t\t\"I\" Wait %s\n", t->name); - else fprintf( out, "+\t\t\"I\" Wait %s\n", command_list[0]); - fflush( out ); - } - XFreeStringList( command_list ); - xtermline = 0; - } + char tname[200], loc[30]; + char **command_list; + int dwidth, dheight, xtermline = 0; + int x1, x2, y1, y2, i, command_count; + long tVx, tVy; + + tname[0] = 0; + + x1 = t->frame_x; + x2 = ScreenWidth - x1 - t->frame_width - 2; + if (x2 < 0) + x2 = 0; + y1 = t->frame_y; + y2 = ScreenHeight - y1 - t->frame_height - 2; + if (y2 < 0) + y2 = 0; + dheight = t->frame_height - t->title_height - 2 * t->boundary_width; + dwidth = t->frame_width - 2 * t->boundary_width; + dwidth -= t->base_width; + dheight -= t->base_height; + if (t->width_inc != 0) + dwidth /= t->width_inc; + if (t->height_inc != 0) + dheight /= t->height_inc; + + if (t->flags & STICKY) { + tVx = 0; + tVy = 0; + } else { + tVx = Vx; + tVy = Vy; + } + snprintf(tname, sizeof(tname), "%dx%d", dwidth, dheight); + if ((t->gravity == EastGravity) || (t->gravity == NorthEastGravity) || + (t->gravity == SouthEastGravity)) + snprintf(loc, sizeof(loc), "-%d", x2); + else + snprintf(loc, sizeof(loc), "+%d", x1 + (int)tVx); + strlcat(tname, loc, sizeof(tname)); + + if ((t->gravity == SouthGravity) || (t->gravity == SouthEastGravity) || + (t->gravity == SouthWestGravity)) + snprintf(loc, sizeof(loc), "-%d", y2); + else + snprintf(loc, sizeof(loc), "+%d", y1 + (int)tVy); + strlcat(tname, loc, sizeof(tname)); + + if (XGetCommand(dpy, t->id, &command_list, &command_count)) { + if (*curdesk != t->desk) { + fprintf(out, "%s\t\"I\" Desk 0 %ld\n", + *isfirstline ? "" : "+", t->desk); + fflush(out); + if (*isfirstline) + *isfirstline = 0; + *curdesk = t->desk; + } + + fprintf(out, "%s\t\t\"I\" Exec ", *isfirstline ? "" : "+"); + if (*isfirstline) + *isfirstline = 0; + fflush(out); + for (i = 0; i < command_count; i++) { + if (strncmp("-geo", command_list[i], 4) == 0) { + i++; + continue; + } + if (strncmp("-ic", command_list[i], 3) == 0) + continue; + if (strncmp("-display", command_list[i], 8) == 0) { + i++; + continue; + } + write_string(out, command_list[i]); + fflush(out); + if (strstr(command_list[i], "xterm")) { + fprintf(out, "-geometry %s ", tname); + if (t->flags & ICONIFIED) + fprintf(out, "-ic "); + xtermline = 1; + fflush(out); + } + } + if (command_count > 0) { + if (xtermline == 0) { + if (t->flags & ICONIFIED) + fprintf(out, "-ic "); + fprintf(out, "-geometry %s &\n", tname); + } else { + fprintf(out, "&\n"); + } + } + if (emit_wait) { + if (t->name) + fprintf(out, "+\t\t\"I\" Wait %s\n", t->name); + else if (command_count > 0) + fprintf(out, "+\t\t\"I\" Wait %s\n", + command_list[0]); + fflush(out); + } + XFreeStringList(command_list); + xtermline = 0; + } } - /*********************************************************************** * * Procedure: @@ -420,52 +409,55 @@ void do_save_command(FILE *out, struct list *t, int *curdesk, * finds time for next action to be performed. * ***********************************************************************/ -void do_save(void) +void +do_save(void) { - struct list *t; - char fnbuf[200]; - FILE *out; - int maxdesk = 0; - int actdesk = -1; - int curdesk; - int isfirstline = 1; - - for (t = list_root; t != NULL; t = t->next) - if (t->desk > maxdesk) - maxdesk = t->desk; - - sprintf(fnbuf, "%s/.fvwm2desk", getenv( "HOME" ) ); - out = fopen( fnbuf, "w" ); - - fprintf( out, "AddToFunc InitFunction"); - fflush ( out ); - - /* - * Generate all Desks except 'CurDesk' - */ - for (curdesk = 0; curdesk <= maxdesk; curdesk++) - { - for (t = list_root; t != NULL; t = t->next) - { - if (t->desk != CurDesk && curdesk == t->desk) - do_save_command(out, t, &actdesk, 1, &isfirstline); - } - } - /* - * Generate 'CurDesk' - */ - for (t = list_root; t != NULL; t = t->next) - { - if (t->desk == CurDesk) - do_save_command(out, t, &actdesk, 0, &isfirstline); - } - - if (actdesk != CurDesk) - fprintf( out, "+\t\"I\" Desk 0 %ld\n", CurDesk); - - fflush( out ); - fclose( out ); - exit(0); + struct list *t; + char fnbuf[200]; + FILE *out; + int maxdesk = 0; + int actdesk = -1; + int curdesk; + int isfirstline = 1; + + for (t = list_root; t != NULL; t = t->next) + if (t->desk > maxdesk) + maxdesk = t->desk; + + snprintf(fnbuf, sizeof(fnbuf), "%s/.fvwm2desk", + getenv("HOME") ? getenv("HOME") : "."); + out = fopen(fnbuf, "w"); + if (out == NULL) { + fprintf(stderr, "%s: couldn't open %s for writing\n", + Myname, fnbuf); + return; + } -} + fprintf(out, "AddToFunc InitFunction"); + fflush(out); + + /* + * Generate all Desks except 'CurDesk' + */ + for (curdesk = 0; curdesk <= maxdesk; curdesk++) { + for (t = list_root; t != NULL; t = t->next) { + if (t->desk != CurDesk && curdesk == t->desk) + do_save_command( + out, t, &actdesk, 1, &isfirstline); + } + } + /* + * Generate 'CurDesk' + */ + for (t = list_root; t != NULL; t = t->next) { + if (t->desk == CurDesk) + do_save_command(out, t, &actdesk, 0, &isfirstline); + } + + if (actdesk != CurDesk) + fprintf(out, "+\t\"I\" Desk 0 %ld\n", CurDesk); + fflush(out); + fclose(out); + exit(0); +} Index: fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.h --- fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.h +++ fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.h @@ -1,40 +1,37 @@ -#include "fvwmlib.h" +#include "fvwmlib.h" #define STICKY 1 -#define ICONIFIED 32 /* is it an icon now? */ +#define ICONIFIED 32 /* is it an icon now? */ -struct list -{ - unsigned long id; - int frame_height; - int frame_width; - int base_width; - int base_height; - int width_inc; - int height_inc; - int frame_x; - int frame_y; - int title_height; - int boundary_width; - unsigned long flags; - unsigned long gravity; - long desk; - struct list *next; - char *name; +struct list { + unsigned long id; + int frame_height; + int frame_width; + int base_width; + int base_height; + int width_inc; + int height_inc; + int frame_x; + int frame_y; + int title_height; + int boundary_width; + unsigned long flags; + unsigned long gravity; + long desk; + struct list *next; + char *name; }; /************************************************************************* * * Subroutine Prototypes - * + * *************************************************************************/ void Loop(int *fd); -void SendInfo(int *fd,char *message,unsigned long window); -char *safemalloc(int length); +void SendInfo(int *fd, char *message, unsigned long window); struct list *find_window(unsigned long id); void add_window(unsigned long new_win, unsigned long *body); void DeadPipe(int nonsense); -void process_message(unsigned long type,unsigned long *body); +void process_message(unsigned long type, unsigned long *body); void do_save(void); void list_new_page(unsigned long *body); - Index: fvwm/modules/FvwmScroll/FvwmScroll.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmScroll/FvwmScroll.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmScroll/FvwmScroll.1 --- fvwm/modules/FvwmScroll/FvwmScroll.1 +++ fvwm/modules/FvwmScroll/FvwmScroll.1 @@ -1,77 +1,53 @@ .\" $OpenBSD: FvwmScroll.1,v 1.1.1.1 2006/11/26 10:53:54 matthieu Exp $ .\" t -.\" @(#)FvwmScroll.1 4/14/94 -.TH FvwmScroll 1 "April 14 1994" 1.20 +.\" @(#)FvwmScroll.1 4/14/94 +.TH FVWMSCROLL 1 "April 14, 1994" "1.20" "FVWM Modules" .UC .SH NAME FvwmScroll \- the FVWM scroll-bar module .SH SYNOPSIS FvwmScroll is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -The FvwmScroll module questions the user to select a target window, if -the module was not launched from within a window context in Fvwm. -After that, it adds scroll bars to the selected window, to reduce the -total desktop space consumed by the window. - - -FvwmScroll reads the same .fvwmrc file as fvwm reads when it starts up, -and looks for lines similar to "*FvwmScrollFore green". - -FvwmScroll should not be used with windows which move or resize -themselves, nor should it be used with windows which set the -WM_COLORMAP_WINDOWS property. Operation is fine with windows that have -a private colormap. - +FvwmScroll questions the user to select a target window if the module was not +launched from within a window context in fvwm. After the selection it adds +scroll bars to the chosen window to reduce the desktop space the client +occupies. +.PP +The module reads the same .fvwmrc file as fvwm at start-up and looks for +entries such as "*FvwmScrollFore green". +.PP +FvwmScroll should not be used with windows that move or resize themselves, nor +with clients that set the WM_COLORMAP_WINDOWS property. It works correctly with +windows that own a private colormap. .SH COPYRIGHTS -The FvwmScroll program, and the concept for -interfacing this module to the Window Manager, are all original work -by Robert Nation. - -Copyright 1994, Robert Nation. No guarantees or -warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - - +The FvwmScroll program, and the concept for interfacing this module to the +window manager, are original work by Robert Nation. +.PP +Copyright 1994, Robert Nation. No guarantees or warranties are provided or +implied. Use this program at your own risk. Permission to use this program for +any purpose is granted, provided the copyright notice remains intact. .SH INITIALIZATION -During initialization, \fIFvwmScroll\fP will eventually search a -configuration file which describes the colors to use. -The configuration file is the same file that fvwm used during initialization. - -If the FvwmScroll executable is linked to another name, ie ln -s -FvwmScroll MoreScroll, then another module called MoreScroll can be -started, with a completely different configuration than FvwmScroll, -simply by changing the keyword FvwmScroll to MoreScroll. - +During initialization, \fIFvwmScroll\fP searches a configuration file that +describes the colors to use. The configuration file is the same one fvwm reads +when it starts. +.PP +If the FvwmScroll executable is linked to another name, for example `ln -s +FvwmScroll MoreScroll`, you can start a module called MoreScroll with a +different configuration simply by changing the keyword FvwmScroll to +MoreScroll. .SH INVOCATION -FvwmScroll can be invoked by binding the action 'Module -FvwmScroll x y' to a menu or key-stroke in the .fvwmrc file. -The parameter x and y are integers, which describe the horizontal and -vertical window size reduction. -Fvwm will search -directory specified in the ModulePath configuration option to attempt -to locate FvwmScroll. Although nothing keeps you from launching -FvwmScroll at start-up time, you probably don't want to. - +FvwmScroll can be invoked by binding the action `Module FvwmScroll x y` to a +menu entry or keystroke in the .fvwmrc file. The parameters \fIx\fP and \fIy\fP +are integers that describe the horizontal and vertical window size reductions. +Fvwm searches the directory specified by the ModulePath option to locate the +module. While you can start FvwmScroll during fvwm initialization, it is +rarely desirable. .SH CONFIGURATION OPTIONS -FvwmScroll reads the same .fvwmrc file as fvwm reads when it starts up, -and looks for lines as listed below: - +FvwmScroll reads the same .fvwmrc file as fvwm at start-up and understands the +following directives: .IP "*FvwmScrollFore \fIcolor\fP" -Tells the module to use \fIcolor\fP instead of grey for scroll bars -themselves. - +Use \fIcolor\fP instead of grey for the scroll bars themselves. .IP "*FvwmScrollBack \fIcolor\fP" -Tells the module to use \fIcolor\fP instead of black for the window -background. - -.SH BUGS -When the scroll bars are removed by clicking on the button in the -lower right corner, the window does not restore its location -correctly. - +Use \fIcolor\fP instead of black for the window background. .SH AUTHOR -Robert Nation - +Robert Nation Index: fvwm/modules/FvwmScroll/FvwmScroll.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmScroll/FvwmScroll.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmScroll/FvwmScroll.c --- fvwm/modules/FvwmScroll/FvwmScroll.c +++ fvwm/modules/FvwmScroll/FvwmScroll.c @@ -11,28 +11,30 @@ #define TRUE 1 #define FALSE 0 -#include "config.h" +#include +#include -#include -#include #include +#include +#include #include -#include -#include + +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" #if HAVE_SYS_SELECT_H #include #endif -#include -#include -#include +#include +#include #include -#include #include -#include -#include +#include #include +#include +#include +#include #include "../../fvwm/module.h" #include "FvwmScroll.h" @@ -41,7 +43,7 @@ char *MyName; int fd_width; int fd[2]; -Display *dpy; /* which display are we talking to */ +Display *dpy; /* which display are we talking to */ Window Root; int screen; int x_fd; @@ -52,8 +54,7 @@ char *BackColor = "black"; Window app_win; -#define MW_EVENTS (ExposureMask | ButtonReleaseMask | KeyReleaseMask) - +#define MW_EVENTS (ExposureMask | ButtonReleaseMask | KeyReleaseMask) /*********************************************************************** * @@ -61,211 +62,197 @@ Window app_win; * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - char *display_name = NULL; - int Clength; - char *tline; - - /* Save the program name for error messages and config parsing */ - temp = argv[0]; - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - Clength = strlen(MyName); - - if(argc < 6) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - if(argc >= 7) - { - extern int Reduction_H; - Reduction_H = atoi(argv[6]); - } - - if(argc >= 8) - { - extern int Reduction_V; - Reduction_V = atoi(argv[7]); - } - - /* Dead pipe == dead fvwm */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - /* An application window may have already been selected - look for it */ - sscanf(argv[4],"%x",(unsigned int *)&app_win); - - /* Open the Display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - x_fd = XConnectionNumber(dpy); - screen= DefaultScreen(dpy); - Root = RootWindow(dpy, screen); - d_depth = DefaultDepth(dpy, screen); - - ScreenHeight = DisplayHeight(dpy,screen); - ScreenWidth = DisplayWidth(dpy,screen); - - /* scan config file for set-up parameters */ - /* Colors and fonts */ - GetConfigLine(fd,&tline); - - while(tline != (char *)0) - { - if(strlen(tline)>1) - { - if(strncasecmp(tline,CatString3(MyName, "Back",""), - Clength+4)==0) - { - CopyString(&BackColor,&tline[Clength+4]); - } + char *temp, *s; + char *display_name = NULL; + int Clength; + char *tline; + + /* Save the program name for error messages and config parsing */ + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + size_t name_len = strlen(temp); + MyName = xmalloc(name_len + 2); + strlcpy(MyName, "*", name_len + 2); + strlcat(MyName, temp, name_len + 2); + Clength = strlen(MyName); + + if (argc < 6) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); } - GetConfigLine(fd,&tline); - } - /* sever our connection with fvwm */ - close(fd[0]); - close(fd[1]); - if(app_win == 0) - GetTargetWindow(&app_win); + if (argc >= 7) { + extern int Reduction_H; + Reduction_H = atoi(argv[6]); + } - if(app_win == 0) - return 0; + if (argc >= 8) { + extern int Reduction_V; + Reduction_V = atoi(argv[7]); + } - fd_width = GetFdWidth(); + /* Dead pipe == dead fvwm */ + signal(SIGPIPE, DeadPipe); - GrabWindow(app_win); - Loop(app_win); - return 0; -} + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + /* An application window may have already been selected - look for it */ + sscanf(argv[4], "%x", (unsigned int *)&app_win); + + /* Open the Display */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + x_fd = XConnectionNumber(dpy); + screen = DefaultScreen(dpy); + Root = RootWindow(dpy, screen); + d_depth = DefaultDepth(dpy, screen); + + ScreenHeight = DisplayHeight(dpy, screen); + ScreenWidth = DisplayWidth(dpy, screen); + + /* scan config file for set-up parameters */ + /* Colors and fonts */ + GetConfigLine(fd, &tline); + + while (tline != (char *)0) { + if (strlen(tline) > 1) { + if (strncasecmp(tline, CatString3(MyName, "Back", ""), + Clength + 4) == 0) { + CopyString(&BackColor, &tline[Clength + 4]); + } + } + GetConfigLine(fd, &tline); + } + + /* sever our connection with fvwm */ + sandbox_x11_only("FvwmScroll"); + close(fd[0]); + close(fd[1]); + if (app_win == 0) + GetTargetWindow(&app_win); + if (app_win == 0) + return 0; + + fd_width = GetFdWidth(); + + GrabWindow(app_win); + Loop(app_win); + return 0; +} /*********************************************************************** * * Detected a broken pipe - time to exit * **********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - extern Atom wm_del_win; + extern Atom wm_del_win; - XReparentWindow(dpy,app_win,Root,0,0); - send_clientmessage (dpy, app_win, wm_del_win, CurrentTime); - XSync(dpy,0); - exit(0); + XReparentWindow(dpy, app_win, Root, 0, 0); + send_clientmessage(dpy, app_win, wm_del_win, CurrentTime); + XSync(dpy, 0); + exit(0); } - /********************************************************************** * * If no application window was indicated on the command line, question * the user to select one * *********************************************************************/ -void GetTargetWindow(Window *app_win) +void +GetTargetWindow(Window *app_win) { - XEvent eventp; - int val = -10,trials; - Window target_win; - - trials = 0; - while((trials <100)&&(val != GrabSuccess)) - { - val=XGrabPointer(dpy, Root, True, - ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, Root, - XCreateFontCursor(dpy,XC_crosshair), - CurrentTime); - if(val != GrabSuccess) - { - usleep(1000); + XEvent eventp; + int val = -10, trials; + Window target_win; + + trials = 0; + while ((trials < 100) && (val != GrabSuccess)) { + val = XGrabPointer(dpy, Root, True, ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, Root, + XCreateFontCursor(dpy, XC_crosshair), CurrentTime); + if (val != GrabSuccess) { + usleep(1000); + } + trials++; + } + if (val != GrabSuccess) { + fprintf(stderr, "%s: Couldn't grab the cursor!\n", MyName); + exit(1); } - trials++; - } - if(val != GrabSuccess) - { - fprintf(stderr,"%s: Couldn't grab the cursor!\n",MyName); - exit(1); - } - XMaskEvent(dpy, ButtonReleaseMask,&eventp); - XUngrabPointer(dpy,CurrentTime); - XSync(dpy,0); - *app_win = eventp.xany.window; - if(eventp.xbutton.subwindow != None) - *app_win = eventp.xbutton.subwindow; - - target_win = ClientWindow(*app_win); - if(target_win != None) - *app_win = target_win; + XMaskEvent(dpy, ButtonReleaseMask, &eventp); + XUngrabPointer(dpy, CurrentTime); + XSync(dpy, 0); + *app_win = eventp.xany.window; + if (eventp.xbutton.subwindow != None) + *app_win = eventp.xbutton.subwindow; + + target_win = ClientWindow(*app_win); + if (target_win != None) + *app_win = target_win; } - -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"FvwmInitBanner: can't %s %s\n", a,b); + fprintf(stderr, "FvwmInitBanner: can't %s %s\n", a, b); } - - /**************************************************************************** * * Find the actual application * ***************************************************************************/ -Window ClientWindow(Window input) +Window +ClientWindow(Window input) { - Atom _XA_WM_STATE; - unsigned int nchildren; - Window root, parent, *children,target; - unsigned long nitems, bytesafter; - unsigned char *prop; - Atom atype; - int aformat; - int i; - - _XA_WM_STATE = XInternAtom (dpy, "WM_STATE", False); - - if (XGetWindowProperty (dpy,input, _XA_WM_STATE , 0L, - 3L , False, _XA_WM_STATE,&atype, - &aformat, &nitems, &bytesafter, - &prop) == Success) - { - if(prop != NULL) - { - XFree(prop); - return input; + Atom _XA_WM_STATE; + unsigned int nchildren; + Window root, parent, *children, target; + unsigned long nitems, bytesafter; + unsigned char *prop; + Atom atype; + int aformat; + int i; + + _XA_WM_STATE = XInternAtom(dpy, "WM_STATE", False); + + if (XGetWindowProperty(dpy, input, _XA_WM_STATE, 0L, 3L, False, + _XA_WM_STATE, &atype, &aformat, &nitems, &bytesafter, + &prop) == Success) { + if (prop != NULL) { + XFree(prop); + return input; + } } - } - - if(!XQueryTree(dpy, input, &root, &parent, &children, &nchildren)) - return None; - - for (i = 0; i < nchildren; i++) - { - target = ClientWindow(children[i]); - if(target != None) - { - XFree((char *)children); - return target; + + if (!XQueryTree(dpy, input, &root, &parent, &children, &nchildren)) + return None; + + for (i = 0; i < nchildren; i++) { + target = ClientWindow(children[i]); + if (target != None) { + XFree((char *)children); + return target; + } } - } - XFree((char *)children); - return None; + XFree((char *)children); + return None; } Index: fvwm/modules/FvwmScroll/FvwmScroll.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmScroll/FvwmScroll.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmScroll/FvwmScroll.h --- fvwm/modules/FvwmScroll/FvwmScroll.h +++ fvwm/modules/FvwmScroll/FvwmScroll.h @@ -1,13 +1,12 @@ -#include "fvwmlib.h" +#include "fvwmlib.h" extern Display *dpy; extern char *MyName; extern Window Root; extern int screen; extern int d_depth; -extern int x_fd,fd_width; +extern int x_fd, fd_width; -char *safemalloc(int length); void DeadPipe(int nonsense); void GetTargetWindow(Window *app_win); void CopyString(char **dest, char *source); @@ -16,19 +15,18 @@ void nocolor(char *a, char *b); char *CatString3(char *a, char *b, char *c); Window ClientWindow(Window input); -void RelieveWindow(Window win,int x,int y,int w,int h, GC rgc,GC sgc); -void CreateWindow(int x, int y,int w, int h); +void RelieveWindow(Window win, int x, int y, int w, int h, GC rgc, GC sgc); +void CreateWindow(int x, int y, int w, int h); Pixel GetShadow(Pixel background); Pixel GetHilite(Pixel background); Pixel GetColor(char *name); void Loop(Window target); void RedrawWindow(Window target); void change_window_name(char *str); -extern void send_clientmessage (Display *disp, Window w, Atom a, Time timestamp); +extern void send_clientmessage(Display *disp, Window w, Atom a, Time timestamp); void GrabWindow(Window target); void change_icon_name(char *str); -void RedrawLeftButton(GC rgc, GC sgc,int x1,int y1); -void RedrawRightButton(GC rgc, GC sgc,int x1,int y1); -void RedrawTopButton(GC rgc, GC sgc,int x1,int y1); -void RedrawBottomButton(GC rgc, GC sgc,int x1,int y1); - +void RedrawLeftButton(GC rgc, GC sgc, int x1, int y1); +void RedrawRightButton(GC rgc, GC sgc, int x1, int y1); +void RedrawTopButton(GC rgc, GC sgc, int x1, int y1); +void RedrawBottomButton(GC rgc, GC sgc, int x1, int y1); Index: fvwm/modules/FvwmScroll/GrabWindow.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmScroll/GrabWindow.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmScroll/GrabWindow.c --- fvwm/modules/FvwmScroll/GrabWindow.c +++ fvwm/modules/FvwmScroll/GrabWindow.c @@ -13,34 +13,31 @@ #include "config.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include -#include +#include +#include + #include +#include +#include #include -#include -#include #if HAVE_SYS_SELECT_H #include #endif -#include -#include -#include -#include "../../fvwm/module.h" - +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include "../../fvwm/module.h" #include "FvwmScroll.h" - int Width = 300, Height = 300; int target_width, target_height; int target_x_offset = 0, target_y_offset = 0; @@ -54,13 +51,14 @@ int Reduction_V = 2; #define PAD_WIDTH2 3 #define PAD_WIDTH3 5 -Window main_win,holder_win; -Pixel back_pix, fore_pix, hilite_pix,shadow_pix; +Window main_win, holder_win; +Pixel back_pix, fore_pix, hilite_pix, shadow_pix; GC ReliefGC, ShadowGC; extern char *BackColor; -#define MW_EVENTS (ExposureMask | StructureNotifyMask| ButtonReleaseMask |\ - ButtonPressMask | ButtonMotionMask | FocusChangeMask) +#define MW_EVENTS \ + (ExposureMask | StructureNotifyMask | ButtonReleaseMask | \ + ButtonPressMask | ButtonMotionMask | FocusChangeMask) Atom wm_del_win; static Atom _XA_WM_PROTOCOLS; @@ -71,146 +69,155 @@ static Atom _XA_WM_COLORMAP_WINDOWS; * Draws the relief pattern around a window * ****************************************************************************/ -void RelieveWindow(Window win,int x,int y,int w,int h, - GC rgc,GC sgc) +void +RelieveWindow(Window win, int x, int y, int w, int h, GC rgc, GC sgc) { - XSegment seg[4]; - int i; - - 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; - - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+1; - - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+1; seg[i++].y2 = y+h-2; - XDrawSegments(dpy, win, rgc, 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; - - seg[i].x1 = x+w-1; seg[i].y1 = y; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - if(d_depth<2) - XDrawSegments(dpy, win, ShadowGC, seg, i); - else - XDrawSegments(dpy, win, sgc, seg, i); - - i=0; - 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-2; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; - - XDrawSegments(dpy, win, sgc, seg, i); + XSegment seg[4]; + int i; + + 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; + + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + 1; + + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + 1; + seg[i++].y2 = y + h - 2; + XDrawSegments(dpy, win, rgc, 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; + + seg[i].x1 = x + w - 1; + seg[i].y1 = y; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + if (d_depth < 2) + XDrawSegments(dpy, win, ShadowGC, seg, i); + else + XDrawSegments(dpy, win, sgc, seg, i); + + i = 0; + 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 - 2; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + + XDrawSegments(dpy, win, sgc, seg, i); } /************************************************************************ * - * Sizes and creates the window + * Sizes and creates the window * ***********************************************************************/ XSizeHints mysizehints; -void CreateWindow(int x,int y, int w, int h) +void +CreateWindow(int x, int y, int w, int h) { - XGCValues gcv; - unsigned long gcm; - - - wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); - _XA_WM_PROTOCOLS = XInternAtom (dpy, "WM_PROTOCOLS", False); - - mysizehints.flags = PWinGravity| PResizeInc | PBaseSize | - PMaxSize | PMinSize | USSize | USPosition; - /* subtract one for the right/bottom border */ - mysizehints.width_inc = 1; - mysizehints.height_inc = 1; - mysizehints.base_height = BAR_WIDTH+PAD_WIDTH3; - mysizehints.base_width = BAR_WIDTH+PAD_WIDTH3; - - Width = w/Reduction_H + BAR_WIDTH + PAD_WIDTH3; - Height = h/Reduction_V + BAR_WIDTH + PAD_WIDTH3; - target_width = w; - target_height = h; - mysizehints.width = Width; - mysizehints.height = Height; - mysizehints.x = x; - mysizehints.y = y; - mysizehints.max_width = w + BAR_WIDTH + PAD_WIDTH3; - mysizehints.max_height = h + BAR_WIDTH + PAD_WIDTH3; - - mysizehints.win_gravity = NorthWestGravity; - - if(d_depth < 2) - { - back_pix = GetColor("black"); - fore_pix = GetColor("white"); - hilite_pix = fore_pix; - shadow_pix = back_pix; - } - else - { - back_pix = GetColor(BackColor); - hilite_pix = GetHilite(back_pix); - shadow_pix = GetShadow(back_pix); - - } - - main_win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y, - mysizehints.width,mysizehints.height, - 0,fore_pix,back_pix); - XSetWMProtocols(dpy,main_win,&wm_del_win,1); - - XSetWMNormalHints(dpy,main_win,&mysizehints); - XSelectInput(dpy,main_win,MW_EVENTS); - change_window_name(MyName); - - holder_win = XCreateSimpleWindow(dpy,main_win,PAD_WIDTH3,PAD_WIDTH3, - mysizehints.width-BAR_WIDTH -PAD_WIDTH3, - mysizehints.height-BAR_WIDTH-PAD_WIDTH3, - 0,fore_pix,back_pix); - XMapWindow(dpy,holder_win); - gcm = GCForeground|GCBackground; - gcv.foreground = hilite_pix; - gcv.background = hilite_pix; - ReliefGC = XCreateGC(dpy, Root, gcm, &gcv); - - gcm = GCForeground|GCBackground; - gcv.foreground = shadow_pix; - gcv.background = shadow_pix; - ShadowGC = XCreateGC(dpy, Root, gcm, &gcv); - - _XA_WM_COLORMAP_WINDOWS = XInternAtom (dpy, "WM_COLORMAP_WINDOWS", False); - } + XGCValues gcv; + unsigned long gcm; + + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + _XA_WM_PROTOCOLS = XInternAtom(dpy, "WM_PROTOCOLS", False); + + mysizehints.flags = PWinGravity | PResizeInc | PBaseSize | PMaxSize | + PMinSize | USSize | USPosition; + /* subtract one for the right/bottom border */ + mysizehints.width_inc = 1; + mysizehints.height_inc = 1; + mysizehints.base_height = BAR_WIDTH + PAD_WIDTH3; + mysizehints.base_width = BAR_WIDTH + PAD_WIDTH3; + + Width = w / Reduction_H + BAR_WIDTH + PAD_WIDTH3; + Height = h / Reduction_V + BAR_WIDTH + PAD_WIDTH3; + target_width = w; + target_height = h; + mysizehints.width = Width; + mysizehints.height = Height; + mysizehints.x = x; + mysizehints.y = y; + mysizehints.max_width = w + BAR_WIDTH + PAD_WIDTH3; + mysizehints.max_height = h + BAR_WIDTH + PAD_WIDTH3; + + mysizehints.win_gravity = NorthWestGravity; + + if (d_depth < 2) { + back_pix = GetColor("black"); + fore_pix = GetColor("white"); + hilite_pix = fore_pix; + shadow_pix = back_pix; + } else { + back_pix = GetColor(BackColor); + hilite_pix = GetHilite(back_pix); + shadow_pix = GetShadow(back_pix); + } + + main_win = XCreateSimpleWindow(dpy, Root, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, 0, fore_pix, back_pix); + XSetWMProtocols(dpy, main_win, &wm_del_win, 1); + + XSetWMNormalHints(dpy, main_win, &mysizehints); + XSelectInput(dpy, main_win, MW_EVENTS); + change_window_name(MyName); + + holder_win = XCreateSimpleWindow(dpy, main_win, PAD_WIDTH3, PAD_WIDTH3, + mysizehints.width - BAR_WIDTH - PAD_WIDTH3, + mysizehints.height - BAR_WIDTH - PAD_WIDTH3, 0, fore_pix, back_pix); + XMapWindow(dpy, holder_win); + gcm = GCForeground | GCBackground; + gcv.foreground = hilite_pix; + gcv.background = hilite_pix; + ReliefGC = XCreateGC(dpy, Root, gcm, &gcv); + + gcm = GCForeground | GCBackground; + gcv.foreground = shadow_pix; + gcv.background = shadow_pix; + ShadowGC = XCreateGC(dpy, Root, gcm, &gcv); + + _XA_WM_COLORMAP_WINDOWS = + XInternAtom(dpy, "WM_COLORMAP_WINDOWS", False); +} /**************************************************************************** - * + * * Loads a single color * - ****************************************************************************/ -Pixel GetColor(char *name) + ****************************************************************************/ +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(dpy,Root,&attributes); - color.pixel = 0; - if (!XParseColor (dpy, attributes.colormap, name, &color)) - { - nocolor("parse",name); - } - else if(!XAllocColor (dpy, attributes.colormap, &color)) - { - nocolor("alloc",name); - } - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(dpy, Root, &attributes); + color.pixel = 0; + if (!XParseColor(dpy, attributes.colormap, name, &color)) { + nocolor("parse", name); + } else if (!XAllocColor(dpy, attributes.colormap, &color)) { + nocolor("alloc", name); + } + return color.pixel; } /*********************************************************************** @@ -229,660 +236,763 @@ Pixel GetColor(char *name) #define NONE 0 int motion = NONE; -void Loop(Window target) +void +Loop(Window target) { - Window root; - int x,y,border_width,depth; - XEvent Event; - int tw,th; - char *temp; - char *prop = NULL; - Atom actual = None; - int actual_format; - unsigned long nitems, bytesafter; - - while(1) - { - XNextEvent(dpy,&Event); - switch(Event.type) - { - case Expose: - exposed = 1; - RedrawWindow(target); - break; - - case ConfigureNotify: - XGetGeometry(dpy,main_win,&root,&x,&y, - (unsigned int *)&tw,(unsigned int *)&th, - (unsigned int *)&border_width, - (unsigned int *)&depth); - if((tw != Width)||(th!= Height)) - { - XResizeWindow(dpy,holder_win,tw-BAR_WIDTH-PAD_WIDTH3, - th-BAR_WIDTH-PAD_WIDTH3); - Width = tw; - Height = th; - if(target_y_offset + Height - BAR_WIDTH > target_height) - target_y_offset = target_height - Height + BAR_WIDTH; - if(target_y_offset < 0) - target_y_offset = 0; - if(target_x_offset < 0) - target_x_offset = 0; - if(target_x_offset + Width - BAR_WIDTH > target_width) - target_x_offset = target_width - Width + BAR_WIDTH; - - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - exposed = 1; - RedrawWindow(target); - } - break; - - case ButtonPress: - if((Event.xbutton.y > Height-BAR_WIDTH) && - (Event.xbutton.x < SCROLL_BAR_WIDTH+PAD_WIDTH3)) - { - motion = LEFT; - exposed = 2; - RedrawWindow(target); - } - else if((Event.xbutton.y > Height-BAR_WIDTH) && - (Event.xbutton.x > Width-BAR_WIDTH-SCROLL_BAR_WIDTH-2) && - (Event.xbutton.x < Width-BAR_WIDTH)) - { - motion = RIGHT; - exposed = 2; - RedrawWindow(target); - } - else if((Event.xbutton.y < SCROLL_BAR_WIDTH+PAD_WIDTH3) && - (Event.xbutton.x > Width-BAR_WIDTH)) - { - motion = TOP; - exposed = 2; - RedrawWindow(target); - } - else if((Event.xbutton.y > Height-BAR_WIDTH-SCROLL_BAR_WIDTH-2) && - (Event.xbutton.y < Height-BAR_WIDTH)&& - (Event.xbutton.x > Width-BAR_WIDTH)) - { - motion = BOTTOM; - exposed = 2; - RedrawWindow(target); - } - else if((Event.xbutton.x > Width - BAR_WIDTH)&& - (Event.xbutton.y < Height- BAR_WIDTH)) - { - - motion = VERTICAL; - target_y_offset=(Event.xbutton.y-PAD_WIDTH3-SCROLL_BAR_WIDTH)* - target_height/ - (Height-BAR_WIDTH-PAD_WIDTH3 - 2*SCROLL_BAR_WIDTH); - if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height) - target_y_offset = target_height - Height+BAR_WIDTH+PAD_WIDTH3; - if(target_y_offset < 0) - target_y_offset = 0; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - RedrawWindow(target); - } - else if((Event.xbutton.y > Height- BAR_WIDTH ) && - (Event.xbutton.x < Width- BAR_WIDTH)) - { - motion=HORIZONTAL; - target_x_offset=(Event.xbutton.x -PAD_WIDTH3-SCROLL_BAR_WIDTH)* - target_width/ - (Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH); - if(target_x_offset < 0) - target_x_offset = 0; - - if(target_x_offset + Width - BAR_WIDTH -PAD_WIDTH3> target_width) - target_x_offset = target_width - Width + BAR_WIDTH+PAD_WIDTH3; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - RedrawWindow(target); - } - else if((Event.xbutton.y > Height- BAR_WIDTH ) && - (Event.xbutton.x > Width- BAR_WIDTH)) - { - exposed = 2; - motion=QUIT; - } - RedrawWindow(target); - break; - - case ButtonRelease: - if((Event.xbutton.y > Height- BAR_WIDTH ) && - (Event.xbutton.x > Width- BAR_WIDTH)&& - (motion==QUIT)) - { - XUnmapWindow(dpy,main_win); - XReparentWindow(dpy,target,Root,x,y); - XSync(dpy,0); - exit(0); - } - if((motion == LEFT)&&(Event.xbutton.y > Height-BAR_WIDTH) && - (Event.xbutton.x < SCROLL_BAR_WIDTH+PAD_WIDTH3)) - { - target_x_offset -= (Width-BAR_WIDTH-PAD_WIDTH2); - if(target_x_offset < 0) - target_x_offset = 0; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - motion = NONE; - exposed = 2; - } - else if((motion == RIGHT)&&(Event.xbutton.y > Height-BAR_WIDTH) && - (Event.xbutton.x > Width-BAR_WIDTH-SCROLL_BAR_WIDTH-2) && - (Event.xbutton.x < Width-BAR_WIDTH)) - { - target_x_offset += (Width-BAR_WIDTH-PAD_WIDTH2); - if(target_x_offset+Width-BAR_WIDTH -PAD_WIDTH3 > target_width) - target_x_offset = target_width - Width+BAR_WIDTH+PAD_WIDTH3; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - motion = NONE; - exposed = 2; - } - else if((motion == TOP)&& - (Event.xbutton.y Width-BAR_WIDTH)) - { - target_y_offset -= (Height-BAR_WIDTH-PAD_WIDTH2); - if(target_y_offset < 0) - target_y_offset = 0; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - motion = NONE; - exposed = 2; - } - else if((motion == BOTTOM)&& - (Event.xbutton.y > Height-BAR_WIDTH-SCROLL_BAR_WIDTH-2) && - (Event.xbutton.y < Height-BAR_WIDTH)&& - (Event.xbutton.x > Width-BAR_WIDTH)) - { - target_y_offset += (Height-BAR_WIDTH-PAD_WIDTH2); - if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height) - target_y_offset = target_height - Height+BAR_WIDTH+PAD_WIDTH3; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - motion = NONE; - exposed = 2; - } - if(motion == VERTICAL) - { - target_y_offset=(Event.xbutton.y-PAD_WIDTH3-SCROLL_BAR_WIDTH)*target_height/ - (Height-BAR_WIDTH-PAD_WIDTH3 - 2*SCROLL_BAR_WIDTH); - if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height) - target_y_offset = target_height - Height+BAR_WIDTH+PAD_WIDTH3; - if(target_y_offset < 0) - target_y_offset = 0; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - } - if(motion == HORIZONTAL) - { - target_x_offset=(Event.xbutton.x -PAD_WIDTH3-SCROLL_BAR_WIDTH)* target_width/ - (Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH); - if(target_x_offset < 0) - target_x_offset = 0; - - if(target_x_offset + Width - BAR_WIDTH -PAD_WIDTH3> target_width) - target_x_offset = target_width - Width + BAR_WIDTH+PAD_WIDTH3; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - } - RedrawWindow(target); - motion = NONE; - break; - - case MotionNotify: - if((motion == LEFT)&&((Event.xmotion.y < Height-BAR_WIDTH) || - (Event.xmotion.x > SCROLL_BAR_WIDTH+PAD_WIDTH3))) - { - motion = NONE; - exposed = 2; - } - else if((motion == RIGHT)&&((Event.xmotion.y < Height-BAR_WIDTH) || - (Event.xmotion.x < Width-BAR_WIDTH-SCROLL_BAR_WIDTH-2) || - (Event.xmotion.x > Width-BAR_WIDTH))) - { - motion = NONE; - exposed = 2; - } - else if((motion == TOP)&& - ((Event.xmotion.y>SCROLL_BAR_WIDTH+PAD_WIDTH3)|| - (Event.xmotion.x < Width-BAR_WIDTH))) - { - motion = NONE; - exposed = 2; - } - else if((motion == BOTTOM)&& - ((Event.xmotion.y < Height-BAR_WIDTH-SCROLL_BAR_WIDTH-2) || - (Event.xmotion.y > Height-BAR_WIDTH)|| - (Event.xmotion.x < Width-BAR_WIDTH))) - { - motion = NONE; - exposed = 2; - } - if(motion == VERTICAL) - { - target_y_offset=(Event.xmotion.y-PAD_WIDTH3-SCROLL_BAR_WIDTH)* - target_height/ - (Height-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH); - if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height) - target_y_offset = target_height - Height+BAR_WIDTH+PAD_WIDTH3; - if(target_y_offset < 0) - target_y_offset = 0; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - } - if(motion == HORIZONTAL) - { - target_x_offset=(Event.xmotion.x -PAD_WIDTH3-SCROLL_BAR_WIDTH)* - target_width/ - (Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH); - if(target_x_offset < 0) - target_x_offset = 0; - - if(target_x_offset + Width - BAR_WIDTH -PAD_WIDTH3> target_width) - target_x_offset = target_width - Width + BAR_WIDTH+PAD_WIDTH3; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - } - if((motion == QUIT)&& - ((Event.xbutton.y < Height- BAR_WIDTH )|| - (Event.xbutton.x < Width- BAR_WIDTH))) - { - motion = NONE; - exposed = 2; - } - RedrawWindow(target); - break; - case ClientMessage: - if ((Event.xclient.format==32) && - (Event.xclient.data.l[0]==wm_del_win)) - { - DeadPipe(1); - } - break; - case PropertyNotify: - if(Event.xproperty.atom == XA_WM_NAME) - { - if(XFetchName(dpy, target, &temp)==0) - temp = NULL; - change_window_name(temp); - } - else if (Event.xproperty.atom == XA_WM_ICON_NAME) - { - if (XGetWindowProperty (dpy, - target, Event.xproperty.atom, 0, - MAX_ICON_NAME_LEN, False, XA_STRING, - &actual,&actual_format, &nitems, - &bytesafter, (unsigned char **) &prop) - == Success && (prop != NULL)) - change_icon_name(prop); - } - else if(Event.xproperty.atom == XA_WM_HINTS) - { - XWMHints *wmhints; - - wmhints = XGetWMHints(dpy,target); - XSetWMHints(dpy,main_win, wmhints); - XFree(wmhints); - } - else if(Event.xproperty.atom == XA_WM_NORMAL_HINTS) - { - /* don't do Normal Hints. They alter the size of the window */ - } - else if (Event.xproperty.atom == _XA_WM_COLORMAP_WINDOWS) - { - } - break; - - case DestroyNotify: - DeadPipe(1); - break; - - case UnmapNotify: - break; - - case MapNotify: - XMapWindow(dpy,main_win); - break; - case FocusIn: - XSetInputFocus(dpy,target,RevertToParent,CurrentTime); - break; - case ColormapNotify: - { - XWindowAttributes xwa; - if(XGetWindowAttributes(dpy,target, &xwa) != 0) - { - XSetWindowColormap(dpy,main_win,xwa.colormap); - } - } - break; - default: - break; + Window root; + int x, y, border_width, depth; + XEvent Event; + int tw, th; + char *temp; + char *prop = NULL; + Atom actual = None; + int actual_format; + unsigned long nitems, bytesafter; + + while (1) { + XNextEvent(dpy, &Event); + switch (Event.type) { + case Expose: + exposed = 1; + RedrawWindow(target); + break; + + case ConfigureNotify: + XGetGeometry(dpy, main_win, &root, &x, &y, + (unsigned int *)&tw, (unsigned int *)&th, + (unsigned int *)&border_width, + (unsigned int *)&depth); + if ((tw != Width) || (th != Height)) { + XResizeWindow(dpy, holder_win, + tw - BAR_WIDTH - PAD_WIDTH3, + th - BAR_WIDTH - PAD_WIDTH3); + Width = tw; + Height = th; + if (target_y_offset + Height - BAR_WIDTH > + target_height) + target_y_offset = + target_height - Height + BAR_WIDTH; + if (target_y_offset < 0) + target_y_offset = 0; + if (target_x_offset < 0) + target_x_offset = 0; + if (target_x_offset + Width - BAR_WIDTH > + target_width) + target_x_offset = + target_width - Width + BAR_WIDTH; + + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + exposed = 1; + RedrawWindow(target); + } + break; + + case ButtonPress: + if ((Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x < SCROLL_BAR_WIDTH + PAD_WIDTH3)) { + motion = LEFT; + exposed = 2; + RedrawWindow(target); + } else if ((Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x > Width - BAR_WIDTH - + SCROLL_BAR_WIDTH - + 2) && + (Event.xbutton.x < Width - BAR_WIDTH)) { + motion = RIGHT; + exposed = 2; + RedrawWindow(target); + } else if ((Event.xbutton.y < + SCROLL_BAR_WIDTH + PAD_WIDTH3) && + (Event.xbutton.x > Width - BAR_WIDTH)) { + motion = TOP; + exposed = 2; + RedrawWindow(target); + } else if ((Event.xbutton.y > Height - BAR_WIDTH - + SCROLL_BAR_WIDTH - + 2) && + (Event.xbutton.y < Height - BAR_WIDTH) && + (Event.xbutton.x > Width - BAR_WIDTH)) { + motion = BOTTOM; + exposed = 2; + RedrawWindow(target); + } else if ((Event.xbutton.x > Width - BAR_WIDTH) && + (Event.xbutton.y < Height - BAR_WIDTH)) { + motion = VERTICAL; + target_y_offset = + (Event.xbutton.y - PAD_WIDTH3 - + SCROLL_BAR_WIDTH) * + target_height / + (Height - BAR_WIDTH - PAD_WIDTH3 - + 2 * SCROLL_BAR_WIDTH); + if (target_y_offset + Height - BAR_WIDTH - + PAD_WIDTH3 > + target_height) + target_y_offset = target_height - + Height + BAR_WIDTH + + PAD_WIDTH3; + if (target_y_offset < 0) + target_y_offset = 0; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + RedrawWindow(target); + } else if ((Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x < Width - BAR_WIDTH)) { + motion = HORIZONTAL; + target_x_offset = + (Event.xbutton.x - PAD_WIDTH3 - + SCROLL_BAR_WIDTH) * + target_width / + (Width - BAR_WIDTH - PAD_WIDTH3 - + 2 * SCROLL_BAR_WIDTH); + if (target_x_offset < 0) + target_x_offset = 0; + + if (target_x_offset + Width - BAR_WIDTH - + PAD_WIDTH3 > + target_width) + target_x_offset = target_width - Width + + BAR_WIDTH + + PAD_WIDTH3; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + RedrawWindow(target); + } else if ((Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x > Width - BAR_WIDTH)) { + exposed = 2; + motion = QUIT; + } + RedrawWindow(target); + break; + + case ButtonRelease: + if ((Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x > Width - BAR_WIDTH) && + (motion == QUIT)) { + XUnmapWindow(dpy, main_win); + { + int root_x, root_y; + Window dummy; + if (XTranslateCoordinates(dpy, main_win, + Root, 0, 0, &root_x, &root_y, + &dummy)) { + XReparentWindow(dpy, target, + Root, root_x, root_y); + } else { + XReparentWindow( + dpy, target, Root, x, y); + } + } + XSync(dpy, 0); + exit(0); + } + if ((motion == LEFT) && + (Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x < SCROLL_BAR_WIDTH + PAD_WIDTH3)) { + target_x_offset -= + (Width - BAR_WIDTH - PAD_WIDTH2); + if (target_x_offset < 0) + target_x_offset = 0; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + motion = NONE; + exposed = 2; + } else if ((motion == RIGHT) && + (Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x > Width - BAR_WIDTH - + SCROLL_BAR_WIDTH - + 2) && + (Event.xbutton.x < Width - BAR_WIDTH)) { + target_x_offset += + (Width - BAR_WIDTH - PAD_WIDTH2); + if (target_x_offset + Width - BAR_WIDTH - + PAD_WIDTH3 > + target_width) + target_x_offset = target_width - Width + + BAR_WIDTH + + PAD_WIDTH3; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + motion = NONE; + exposed = 2; + } else if ((motion == TOP) && + (Event.xbutton.y < + SCROLL_BAR_WIDTH + PAD_WIDTH3) && + (Event.xbutton.x > Width - BAR_WIDTH)) { + target_y_offset -= + (Height - BAR_WIDTH - PAD_WIDTH2); + if (target_y_offset < 0) + target_y_offset = 0; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + motion = NONE; + exposed = 2; + } else if ((motion == BOTTOM) && + (Event.xbutton.y > Height - BAR_WIDTH - + SCROLL_BAR_WIDTH - + 2) && + (Event.xbutton.y < Height - BAR_WIDTH) && + (Event.xbutton.x > Width - BAR_WIDTH)) { + target_y_offset += + (Height - BAR_WIDTH - PAD_WIDTH2); + if (target_y_offset + Height - BAR_WIDTH - + PAD_WIDTH3 > + target_height) + target_y_offset = target_height - + Height + BAR_WIDTH + + PAD_WIDTH3; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + motion = NONE; + exposed = 2; + } + if (motion == VERTICAL) { + target_y_offset = + (Event.xbutton.y - PAD_WIDTH3 - + SCROLL_BAR_WIDTH) * + target_height / + (Height - BAR_WIDTH - PAD_WIDTH3 - + 2 * SCROLL_BAR_WIDTH); + if (target_y_offset + Height - BAR_WIDTH - + PAD_WIDTH3 > + target_height) + target_y_offset = target_height - + Height + BAR_WIDTH + + PAD_WIDTH3; + if (target_y_offset < 0) + target_y_offset = 0; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + } + if (motion == HORIZONTAL) { + target_x_offset = + (Event.xbutton.x - PAD_WIDTH3 - + SCROLL_BAR_WIDTH) * + target_width / + (Width - BAR_WIDTH - PAD_WIDTH3 - + 2 * SCROLL_BAR_WIDTH); + if (target_x_offset < 0) + target_x_offset = 0; + + if (target_x_offset + Width - BAR_WIDTH - + PAD_WIDTH3 > + target_width) + target_x_offset = target_width - Width + + BAR_WIDTH + + PAD_WIDTH3; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + } + RedrawWindow(target); + motion = NONE; + break; + + case MotionNotify: + if ((motion == LEFT) && + ((Event.xmotion.y < Height - BAR_WIDTH) || + (Event.xmotion.x > + SCROLL_BAR_WIDTH + PAD_WIDTH3))) { + motion = NONE; + exposed = 2; + } else if ((motion == RIGHT) && + ((Event.xmotion.y < Height - BAR_WIDTH) || + (Event.xmotion.x < Width - BAR_WIDTH - + SCROLL_BAR_WIDTH - + 2) || + (Event.xmotion.x > Width - BAR_WIDTH))) { + motion = NONE; + exposed = 2; + } else if ((motion == TOP) && + ((Event.xmotion.y > + SCROLL_BAR_WIDTH + PAD_WIDTH3) || + (Event.xmotion.x < Width - BAR_WIDTH))) { + motion = NONE; + exposed = 2; + } else if ((motion == BOTTOM) && + ((Event.xmotion.y < Height - BAR_WIDTH - + SCROLL_BAR_WIDTH - + 2) || + (Event.xmotion.y > Height - BAR_WIDTH) || + (Event.xmotion.x < Width - BAR_WIDTH))) { + motion = NONE; + exposed = 2; + } + if (motion == VERTICAL) { + target_y_offset = + (Event.xmotion.y - PAD_WIDTH3 - + SCROLL_BAR_WIDTH) * + target_height / + (Height - BAR_WIDTH - PAD_WIDTH3 - + 2 * SCROLL_BAR_WIDTH); + if (target_y_offset + Height - BAR_WIDTH - + PAD_WIDTH3 > + target_height) + target_y_offset = target_height - + Height + BAR_WIDTH + + PAD_WIDTH3; + if (target_y_offset < 0) + target_y_offset = 0; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + } + if (motion == HORIZONTAL) { + target_x_offset = + (Event.xmotion.x - PAD_WIDTH3 - + SCROLL_BAR_WIDTH) * + target_width / + (Width - BAR_WIDTH - PAD_WIDTH3 - + 2 * SCROLL_BAR_WIDTH); + if (target_x_offset < 0) + target_x_offset = 0; + + if (target_x_offset + Width - BAR_WIDTH - + PAD_WIDTH3 > + target_width) + target_x_offset = target_width - Width + + BAR_WIDTH + + PAD_WIDTH3; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + } + if ((motion == QUIT) && + ((Event.xbutton.y < Height - BAR_WIDTH) || + (Event.xbutton.x < Width - BAR_WIDTH))) { + motion = NONE; + exposed = 2; + } + RedrawWindow(target); + break; + case ClientMessage: + if ((Event.xclient.format == 32) && + (Event.xclient.data.l[0] == wm_del_win)) { + DeadPipe(1); + } + break; + case PropertyNotify: + if (Event.xproperty.atom == XA_WM_NAME) { + if (XFetchName(dpy, target, &temp) == 0) + temp = NULL; + change_window_name(temp); + } else if (Event.xproperty.atom == XA_WM_ICON_NAME) { + if (XGetWindowProperty(dpy, target, + Event.xproperty.atom, 0, + MAX_ICON_NAME_LEN, False, XA_STRING, + &actual, &actual_format, &nitems, + &bytesafter, + (unsigned char **)&prop) == Success && + (prop != NULL)) { + change_icon_name(prop); + XFree(prop); + } + } else if (Event.xproperty.atom == XA_WM_HINTS) { + XWMHints *wmhints; + + wmhints = XGetWMHints(dpy, target); + if (wmhints != NULL) { + XSetWMHints(dpy, main_win, wmhints); + XFree(wmhints); + } + } else if (Event.xproperty.atom == XA_WM_NORMAL_HINTS) { + /* don't do Normal Hints. They alter the size of + * the window */ + } else if (Event.xproperty.atom == + _XA_WM_COLORMAP_WINDOWS) { + } + break; + + case DestroyNotify: + DeadPipe(1); + break; + + case UnmapNotify: + break; + + case MapNotify: + XMapWindow(dpy, main_win); + break; + case FocusIn: + XSetInputFocus( + dpy, target, RevertToParent, CurrentTime); + break; + case ColormapNotify: { + XWindowAttributes xwa; + if (XGetWindowAttributes(dpy, target, &xwa) != 0) { + XSetWindowColormap(dpy, main_win, xwa.colormap); + } + } + break; + default: + break; + } } - } - return; + return; } - - /************************************************************************ * - * Draw the window + * Draw the window * ***********************************************************************/ -void RedrawWindow(Window target) +void +RedrawWindow(Window target) { - static int xv= 0,yv= 0,hv=0,wv=0; - static int xh=0,yh=0,hh=0,wh=0; - int x,y,w,h; - XEvent dummy; - - while (XCheckTypedWindowEvent (dpy, main_win, Expose, &dummy)) - exposed |= 1; - - XSetWindowBorderWidth(dpy,target,0); - - RelieveWindow(main_win,PAD_WIDTH3-2,PAD_WIDTH3-2, - Width-BAR_WIDTH-PAD_WIDTH3+4, - Height-BAR_WIDTH-PAD_WIDTH3+4,ShadowGC,ReliefGC); - - y = (Height-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH)* - target_y_offset/target_height - + PAD_WIDTH2 + 2 + SCROLL_BAR_WIDTH; - x = Width-SCROLL_BAR_WIDTH- PAD_WIDTH2-2; - w = SCROLL_BAR_WIDTH; - h = (Height-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH)* - (Height-BAR_WIDTH-PAD_WIDTH3)/ - target_height; - if((y!=yv)||(x != xv)||(w != wv)||(h != hv)||(exposed & 1)) - { - yv = y; - xv = x; - wv = w; - hv = h; - XClearArea(dpy,main_win,x,PAD_WIDTH3+SCROLL_BAR_WIDTH, - w,Height-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH,False); - - RelieveWindow(main_win,x,y,w,h,ReliefGC,ShadowGC); - } - if(exposed & 1) - RelieveWindow(main_win,x-2,PAD_WIDTH2, - w+4,Height-BAR_WIDTH-PAD_WIDTH2+2,ShadowGC,ReliefGC); - if(exposed) - { - if(motion == TOP) - RedrawTopButton(ShadowGC,ReliefGC,x,PAD_WIDTH3); - else - RedrawTopButton(ReliefGC,ShadowGC,x,PAD_WIDTH3); - if(motion == BOTTOM) - RedrawBottomButton(ShadowGC,ReliefGC,x, - Height-BAR_WIDTH-SCROLL_BAR_WIDTH); - else - RedrawBottomButton(ReliefGC,ShadowGC,x, - Height-BAR_WIDTH-SCROLL_BAR_WIDTH); - } - - x = (Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH)*target_x_offset/ - target_width+PAD_WIDTH2+2 + SCROLL_BAR_WIDTH; - y = Height-SCROLL_BAR_WIDTH-PAD_WIDTH2-2; - w = (Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH)* - (Width-BAR_WIDTH-PAD_WIDTH3)/target_width; - h = SCROLL_BAR_WIDTH; - if((y!=yh)||(x != xh)||(w != wh)||(h != hh)||(exposed & 1)) - { - yh = y; - xh = x; - wh = w; - hh = h; - XClearArea(dpy,main_win,PAD_WIDTH3+SCROLL_BAR_WIDTH,y, - Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH,h,False); - RelieveWindow(main_win,x,y,w,h,ReliefGC,ShadowGC); - } - if(exposed& 1) - { - RelieveWindow(main_win,PAD_WIDTH2,y-2,Width-BAR_WIDTH-PAD_WIDTH2+2,h+4, - ShadowGC,ReliefGC); - } - if(exposed) - { - if(motion == LEFT) - RedrawLeftButton(ShadowGC,ReliefGC,PAD_WIDTH3,y); - else - RedrawLeftButton(ReliefGC,ShadowGC,PAD_WIDTH3,y); - if(motion ==RIGHT) - RedrawRightButton(ShadowGC,ReliefGC, - Width-BAR_WIDTH-SCROLL_BAR_WIDTH,y); - else - RedrawRightButton(ReliefGC,ShadowGC, - Width-BAR_WIDTH-SCROLL_BAR_WIDTH,y); - } - - if(exposed) - { - XClearArea(dpy,main_win,Width-BAR_WIDTH+2, - Height-BAR_WIDTH+2,BAR_WIDTH-3,BAR_WIDTH-3,False); - if(motion == QUIT) - RelieveWindow(main_win,Width-SCROLL_BAR_WIDTH-PAD_WIDTH2-4, - Height-SCROLL_BAR_WIDTH-PAD_WIDTH2-4, - SCROLL_BAR_WIDTH+4,SCROLL_BAR_WIDTH+4, - ShadowGC,ReliefGC); - else - RelieveWindow(main_win,Width-SCROLL_BAR_WIDTH-PAD_WIDTH2-4, - Height-SCROLL_BAR_WIDTH-PAD_WIDTH2-4, - SCROLL_BAR_WIDTH+4,SCROLL_BAR_WIDTH+4, - ReliefGC,ShadowGC); - } - exposed = 0; -} + static int xv = 0, yv = 0, hv = 0, wv = 0; + static int xh = 0, yh = 0, hh = 0, wh = 0; + int x, y, w, h; + XEvent dummy; + + while (XCheckTypedWindowEvent(dpy, main_win, Expose, &dummy)) + exposed |= 1; + + XSetWindowBorderWidth(dpy, target, 0); + + RelieveWindow(main_win, PAD_WIDTH3 - 2, PAD_WIDTH3 - 2, + Width - BAR_WIDTH - PAD_WIDTH3 + 4, + Height - BAR_WIDTH - PAD_WIDTH3 + 4, ShadowGC, ReliefGC); + + y = (Height - BAR_WIDTH - PAD_WIDTH3 - 2 * SCROLL_BAR_WIDTH) * + target_y_offset / target_height + + PAD_WIDTH2 + 2 + SCROLL_BAR_WIDTH; + x = Width - SCROLL_BAR_WIDTH - PAD_WIDTH2 - 2; + w = SCROLL_BAR_WIDTH; + h = (Height - BAR_WIDTH - PAD_WIDTH3 - 2 * SCROLL_BAR_WIDTH) * + (Height - BAR_WIDTH - PAD_WIDTH3) / target_height; + if ((y != yv) || (x != xv) || (w != wv) || (h != hv) || (exposed & 1)) { + yv = y; + xv = x; + wv = w; + hv = h; + XClearArea(dpy, main_win, x, PAD_WIDTH3 + SCROLL_BAR_WIDTH, w, + Height - BAR_WIDTH - PAD_WIDTH3 - 2 * SCROLL_BAR_WIDTH, + False); + + RelieveWindow(main_win, x, y, w, h, ReliefGC, ShadowGC); + } + if (exposed & 1) + RelieveWindow(main_win, x - 2, PAD_WIDTH2, w + 4, + Height - BAR_WIDTH - PAD_WIDTH2 + 2, ShadowGC, ReliefGC); + if (exposed) { + if (motion == TOP) + RedrawTopButton(ShadowGC, ReliefGC, x, PAD_WIDTH3); + else + RedrawTopButton(ReliefGC, ShadowGC, x, PAD_WIDTH3); + if (motion == BOTTOM) + RedrawBottomButton(ShadowGC, ReliefGC, x, + Height - BAR_WIDTH - SCROLL_BAR_WIDTH); + else + RedrawBottomButton(ReliefGC, ShadowGC, x, + Height - BAR_WIDTH - SCROLL_BAR_WIDTH); + } + x = (Width - BAR_WIDTH - PAD_WIDTH3 - 2 * SCROLL_BAR_WIDTH) * + target_x_offset / target_width + + PAD_WIDTH2 + 2 + SCROLL_BAR_WIDTH; + y = Height - SCROLL_BAR_WIDTH - PAD_WIDTH2 - 2; + w = (Width - BAR_WIDTH - PAD_WIDTH3 - 2 * SCROLL_BAR_WIDTH) * + (Width - BAR_WIDTH - PAD_WIDTH3) / target_width; + h = SCROLL_BAR_WIDTH; + if ((y != yh) || (x != xh) || (w != wh) || (h != hh) || (exposed & 1)) { + yh = y; + xh = x; + wh = w; + hh = h; + XClearArea(dpy, main_win, PAD_WIDTH3 + SCROLL_BAR_WIDTH, y, + Width - BAR_WIDTH - PAD_WIDTH3 - 2 * SCROLL_BAR_WIDTH, h, + False); + RelieveWindow(main_win, x, y, w, h, ReliefGC, ShadowGC); + } + if (exposed & 1) { + RelieveWindow(main_win, PAD_WIDTH2, y - 2, + Width - BAR_WIDTH - PAD_WIDTH2 + 2, h + 4, ShadowGC, + ReliefGC); + } + if (exposed) { + if (motion == LEFT) + RedrawLeftButton(ShadowGC, ReliefGC, PAD_WIDTH3, y); + else + RedrawLeftButton(ReliefGC, ShadowGC, PAD_WIDTH3, y); + if (motion == RIGHT) + RedrawRightButton(ShadowGC, ReliefGC, + Width - BAR_WIDTH - SCROLL_BAR_WIDTH, y); + else + RedrawRightButton(ReliefGC, ShadowGC, + Width - BAR_WIDTH - SCROLL_BAR_WIDTH, y); + } + + if (exposed) { + XClearArea(dpy, main_win, Width - BAR_WIDTH + 2, + Height - BAR_WIDTH + 2, BAR_WIDTH - 3, BAR_WIDTH - 3, + False); + if (motion == QUIT) + RelieveWindow(main_win, + Width - SCROLL_BAR_WIDTH - PAD_WIDTH2 - 4, + Height - SCROLL_BAR_WIDTH - PAD_WIDTH2 - 4, + SCROLL_BAR_WIDTH + 4, SCROLL_BAR_WIDTH + 4, + ShadowGC, ReliefGC); + else + RelieveWindow(main_win, + Width - SCROLL_BAR_WIDTH - PAD_WIDTH2 - 4, + Height - SCROLL_BAR_WIDTH - PAD_WIDTH2 - 4, + SCROLL_BAR_WIDTH + 4, SCROLL_BAR_WIDTH + 4, + ReliefGC, ShadowGC); + } + exposed = 0; +} /************************************************************************** * Change the window name displayed in the title bar. **************************************************************************/ -void change_window_name(char *str) +void +change_window_name(char *str) { - XTextProperty name; - - if(str == NULL) - return; - - if (XStringListToTextProperty(&str,1,&name) == 0) - { - fprintf(stderr,"%s: cannot allocate window name",MyName); - return; - } - XSetWMName(dpy,main_win,&name); - XFree(name.value); -} + XTextProperty name; + + if (str == NULL) + return; + if (XStringListToTextProperty(&str, 1, &name) == 0) { + fprintf(stderr, "%s: cannot allocate window name", MyName); + return; + } + XSetWMName(dpy, main_win, &name); + XFree(name.value); +} /************************************************************************** * Change the window name displayed in the icon. **************************************************************************/ -void change_icon_name(char *str) +void +change_icon_name(char *str) { - XTextProperty name; - - if(str == NULL)return; - if (XStringListToTextProperty(&str,1,&name) == 0) - { - fprintf(stderr,"%s: cannot allocate window name",MyName); - return; - } - XSetWMIconName(dpy,main_win,&name); - XFree(name.value); -} - + XTextProperty name; -void GrabWindow(Window target) -{ - char *temp; - Window Junk,root; - unsigned int tw,th,border_width,depth; - int x,y; - char *prop = NULL; - Atom actual = None; - int actual_format; - unsigned long nitems, bytesafter; - - XUnmapWindow(dpy,target); - XSync(dpy,0); - XGetGeometry(dpy,target,&root,&x,&y, - (unsigned int *)&tw,(unsigned int *)&th, - (unsigned int *)&border_width, - (unsigned int *)&depth); - XSync(dpy,0); - - XTranslateCoordinates(dpy, target, Root, 0, 0, &x,&y, &Junk); - - InitPictureCMap(dpy,Root); /* store the window cmap for GetShadow */ - - CreateWindow(x,y,tw,th); - XSetWindowBorderWidth(dpy,target,0); - XReparentWindow(dpy,target, holder_win,0,0); - XMapWindow(dpy,target); - XSelectInput(dpy,target, PropertyChangeMask|StructureNotifyMask| - ColormapChangeMask); - if(XFetchName(dpy, target, &temp)==0) - temp = NULL; - if (XGetWindowProperty (dpy, - target, XA_WM_ICON_NAME, 0, - MAX_ICON_NAME_LEN, False, XA_STRING, - &actual,&actual_format, &nitems, - &bytesafter, (unsigned char **) &prop) - == Success && (prop != NULL)) - { - change_icon_name(prop); - XFree(prop); - } - change_window_name(temp); - { - XWMHints *wmhints; - - wmhints = XGetWMHints(dpy,target); - if(wmhints != NULL) - { - XSetWMHints(dpy,main_win, wmhints); - XFree(wmhints); - } - } - { - XWindowAttributes xwa; - if(XGetWindowAttributes(dpy,target, &xwa) != 0) - { - XSetWindowColormap(dpy,main_win,xwa.colormap); - } - } - - XMapWindow(dpy,main_win); - RedrawWindow(target); - XFree(temp); + if (str == NULL) + return; + if (XStringListToTextProperty(&str, 1, &name) == 0) { + fprintf(stderr, "%s: cannot allocate window name", MyName); + return; + } + XSetWMIconName(dpy, main_win, &name); + XFree(name.value); } - - - - -void RedrawLeftButton(GC rgc, GC sgc,int x1,int y1) +void +GrabWindow(Window target) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = x1+1; seg[i].y1 = y1+SCROLL_BAR_WIDTH/2; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+1; - - seg[i].x1 = x1; seg[i].y1 = y1+SCROLL_BAR_WIDTH/2; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1; - XDrawSegments(dpy, main_win, rgc, seg, i); - - i = 0; - seg[i].x1 = x1+1; seg[i].y1 =y1+ SCROLL_BAR_WIDTH/2; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 =y1+ SCROLL_BAR_WIDTH - 2; - - seg[i].x1 = x1; seg[i].y1 = y1+SCROLL_BAR_WIDTH/2; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; + char *temp; + Window Junk, root; + unsigned int tw, th, border_width, depth; + int x, y; + char *prop = NULL; + Atom actual = None; + int actual_format; + unsigned long nitems, bytesafter; + + XUnmapWindow(dpy, target); + XSync(dpy, 0); + XGetGeometry(dpy, target, &root, &x, &y, (unsigned int *)&tw, + (unsigned int *)&th, (unsigned int *)&border_width, + (unsigned int *)&depth); + XSync(dpy, 0); + + XTranslateCoordinates(dpy, target, Root, 0, 0, &x, &y, &Junk); + + InitPictureCMap(dpy, Root); /* store the window cmap for GetShadow */ + + CreateWindow(x, y, tw, th); + XSetWindowBorderWidth(dpy, target, 0); + XReparentWindow(dpy, target, holder_win, 0, 0); + XMapWindow(dpy, target); + XSelectInput(dpy, target, + PropertyChangeMask | StructureNotifyMask | ColormapChangeMask); + if (XFetchName(dpy, target, &temp) == 0) + temp = NULL; + if (XGetWindowProperty(dpy, target, XA_WM_ICON_NAME, 0, + MAX_ICON_NAME_LEN, False, XA_STRING, &actual, &actual_format, + &nitems, &bytesafter, (unsigned char **)&prop) == Success && + (prop != NULL)) { + change_icon_name(prop); + XFree(prop); + } + change_window_name(temp); + { + XWMHints *wmhints; - seg[i].x1 = x1+SCROLL_BAR_WIDTH - 2; seg[i].y1 = y1+1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; + wmhints = XGetWMHints(dpy, target); + if (wmhints != NULL) { + XSetWMHints(dpy, main_win, wmhints); + XFree(wmhints); + } + } + { + XWindowAttributes xwa; + if (XGetWindowAttributes(dpy, target, &xwa) != 0) { + XSetWindowColormap(dpy, main_win, xwa.colormap); + } + } - seg[i].x1 = x1+SCROLL_BAR_WIDTH - 1; seg[i].y1 = y1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - XDrawSegments(dpy,main_win, sgc, seg, i); + XMapWindow(dpy, main_win); + RedrawWindow(target); + XFree(temp); } -void RedrawRightButton(GC rgc, GC sgc,int x1,int y1) +void +RedrawLeftButton(GC rgc, GC sgc, int x1, int y1) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = x1+1; seg[i].y1 = y1+1; - seg[i].x2 = x1+1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; - - seg[i].x1 = x1; seg[i].y1 = y1; - seg[i].x2 = x1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - - seg[i].x1 = x1+1; seg[i].y1 = y1+1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH/2; - - seg[i].x1 = x1; seg[i].y1 = y1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH/2; - - XDrawSegments(dpy, main_win, rgc, seg, i); - - i = 0; - seg[i].x1 = x1; seg[i].y1 = y1+SCROLL_BAR_WIDTH - 2; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH/2; - - seg[i].x1 = x1; seg[i].y1 = y1+SCROLL_BAR_WIDTH - 1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH/2; - XDrawSegments(dpy,main_win, sgc, seg, i); + XSegment seg[4]; + int i = 0; + + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH / 2; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + 1; + + seg[i].x1 = x1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH / 2; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1; + XDrawSegments(dpy, main_win, rgc, seg, i); + + i = 0; + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH / 2; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH / 2; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + + seg[i].x1 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i].y1 = y1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + XDrawSegments(dpy, main_win, sgc, seg, i); } -void RedrawTopButton(GC rgc, GC sgc,int x1,int y1) +void +RedrawRightButton(GC rgc, GC sgc, int x1, int y1) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = x1+SCROLL_BAR_WIDTH/2; seg[i].y1 = y1+1; - seg[i].x2 = x1+1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; - - seg[i].x1 = x1+SCROLL_BAR_WIDTH/2; seg[i].y1 = y1; - seg[i].x2 = x1+0; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - XDrawSegments(dpy, main_win, rgc, seg, i); - - i = 0; - seg[i].x1 = x1+SCROLL_BAR_WIDTH/2; seg[i].y1 = y1+1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; - - seg[i].x1 = x1+SCROLL_BAR_WIDTH/2; seg[i].y1 = y1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - - seg[i].x1 = x1+1; seg[i].y1 = y1+SCROLL_BAR_WIDTH - 2; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; - - seg[i].x1 = x1+0; seg[i].y1 = y1+SCROLL_BAR_WIDTH - 1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - XDrawSegments(dpy,main_win, sgc, seg, i); + XSegment seg[4]; + int i = 0; + + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1; + seg[i].y1 = y1; + seg[i].x2 = x1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH / 2; + + seg[i].x1 = x1; + seg[i].y1 = y1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH / 2; + + XDrawSegments(dpy, main_win, rgc, seg, i); + + i = 0; + seg[i].x1 = x1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH - 2; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH / 2; + + seg[i].x1 = x1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH - 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH / 2; + XDrawSegments(dpy, main_win, sgc, seg, i); } -void RedrawBottomButton(GC rgc, GC sgc,int x1, int y1) +void +RedrawTopButton(GC rgc, GC sgc, int x1, int y1) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = x1+1; seg[i].y1 = y1+1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH/2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; - - seg[i].x1 = x1; seg[i].y1 = y1+0; - seg[i].x2 = x1+SCROLL_BAR_WIDTH/2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - - seg[i].x1 = x1+1; seg[i].y1 = y1+1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+1; - - seg[i].x1 = x1; seg[i].y1 = y1+0; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+0; - XDrawSegments(dpy,main_win, rgc, seg, i); - - i = 0; - seg[i].x1 = x1+SCROLL_BAR_WIDTH - 2; seg[i].y1 = y1+1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH/2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; + XSegment seg[4]; + int i = 0; + + seg[i].x1 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i].y1 = y1; + seg[i].x2 = x1 + 0; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + XDrawSegments(dpy, main_win, rgc, seg, i); + + i = 0; + seg[i].x1 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i].y1 = y1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH - 2; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1 + 0; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH - 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + XDrawSegments(dpy, main_win, sgc, seg, i); +} - seg[i].x1 = x1+SCROLL_BAR_WIDTH - 1; seg[i].y1 = y1+0; - seg[i].x2 = x1+SCROLL_BAR_WIDTH/2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - XDrawSegments(dpy, main_win, sgc, seg, i); +void +RedrawBottomButton(GC rgc, GC sgc, int x1, int y1) +{ + XSegment seg[4]; + int i = 0; + + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1; + seg[i].y1 = y1 + 0; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + 1; + + seg[i].x1 = x1; + seg[i].y1 = y1 + 0; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + 0; + XDrawSegments(dpy, main_win, rgc, seg, i); + + i = 0; + seg[i].x1 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i].y1 = y1 + 0; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + XDrawSegments(dpy, main_win, sgc, seg, i); } - Index: fvwm/modules/FvwmTalk/FvwmTalk.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmTalk/FvwmTalk.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmTalk/FvwmTalk.1 --- fvwm/modules/FvwmTalk/FvwmTalk.1 +++ fvwm/modules/FvwmTalk/FvwmTalk.1 @@ -1,47 +1,36 @@ .\" $OpenBSD: FvwmTalk.1,v 1.1.1.1 2006/11/26 10:53:55 matthieu Exp $ .\" t -.\" @(#)FvwmTalk.1 1/12/94 -.TH FvwmTalk 1 "Jan 28 1994" 1.20 +.\" @(#)FvwmTalk.1 1/12/94 +.TH FVWMTALK 1 "January 28, 1994" "1.20" "FVWM Modules" .UC .SH NAME FvwmTalk \- the FVWM command line interface .SH SYNOPSIS FvwmTalk is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -The FvwmTalk allows the user to type fvwm commands into a window, and -have them executed immediately. These commands are usually specfified -in the .fvwmrc file, or are bound to menu/mouse items as specified -in that file. This tools is particularly useful for testing new -configuration ideas, or for implementing temporary changes to your +FvwmTalk allows the user to type fvwm commands into a window and execute them +immediately. These commands are usually specified in the .fvwmrc file or are +bound to menu or mouse items defined there. The tool is particularly useful for +testing new configuration ideas or implementing temporary changes to the environment. - .SH COPYRIGHTS -The FvwmTalk program, and the concept for -interfacing this module to the Window Manager, are all original work -by Robert Nation - -Copyright 1994, Robert Nation. No guarantees or warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - - +The FvwmTalk program, and the concept for interfacing this module to the window +manager, are original work by Robert Nation. +.PP +Copyright 1994, Robert Nation. No guarantees or warranties are provided or +implied. Use this program at your own risk. Permission to use this program for +any purpose is granted, provided the copyright notice remains intact. .SH INITIALIZATION -So kill me, I can't remember what goes on. - +FvwmTalk does not require explicit initialization beyond fvwm's own module +startup sequence. .SH INVOCATION -FvwmTalk can be invoked by inserting the line 'Module FvwmTalk' in -the .fvwmrc file. This can be placed on a line by itself, if FvwmTalk -is to be spawned during fvwm's initialization, or can be bound to a -menu or mouse button or keystroke to invoke it later. Fvwm will search -directory specified in the ModulePath configuration option to attempt -to locate FvwmTalk. - +FvwmTalk can be invoked by inserting the line `Module FvwmTalk` in the .fvwmrc +file. This can be placed on its own line if FvwmTalk is to be spawned during +fvwm initialization, or it can be bound to a menu, mouse button, or keystroke +to launch it later. Fvwm searches the directory specified in the ModulePath +option to locate the module. .SH CONFIGURATION OPTIONS -I plead ignorance here. Read the code. - - +FvwmTalk accepts the standard fvwm module command-line options. Consult the +source code for the complete list of supported arguments. .SH AUTHOR Robert Nation - Index: fvwm/modules/FvwmTalk/FvwmTalk.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmTalk/FvwmTalk.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmTalk/FvwmTalk.c --- fvwm/modules/FvwmTalk/FvwmTalk.c +++ fvwm/modules/FvwmTalk/FvwmTalk.c @@ -15,39 +15,37 @@ #define PROP_SIZE 1024 #include "config.h" +#include "../../fvwm/fvwm_sandbox.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include -#include +#include +#include + #include +#include +#include #include -#include -#include #if HAVE_SYS_SELECT_H #include #endif -#include -#include -#include +#include +#include #include -#include - -#include #include -#include -#include +#include +#include +#include +#include +#include #include "../../fvwm/module.h" - #include "FvwmTalk.h" char *MyName; -int fd_width,screen, d_depth; +int fd_width, screen, d_depth; int fd[2]; int x_fd; @@ -60,26 +58,25 @@ char *BackColor = "black"; char *display_name = NULL; XFontStruct *font; -Pixel fore_pix,back_pix; +Pixel fore_pix, back_pix; static Atom wm_del_win; unsigned long valuemask; XSetWindowAttributes attributes; XWMHints wmhints; Window window; -char last_error[256],previous_line[256]; +char last_error[256], previous_line[256]; char Text[256]; int pos = 0; -XSizeHints sizehints = -{ - (PMinSize | PResizeInc | PBaseSize | PWinGravity | PMaxSize), - 0, 0, 100, 100, /* x, y, width and height */ - 1, 1, /* Min width and height */ - 0, 0, /* Max width and height */ - 1, 1, /* Width and height increments */ - {0, 0}, {0, 0}, /* Aspect ratio - not used */ - 1, 1, /* base size */ - (NorthWestGravity) /* gravity */ +XSizeHints sizehints = { + (PMinSize | PResizeInc | PBaseSize | PWinGravity | PMaxSize), 0, 0, 100, + 100, /* x, y, width and height */ + 1, 1, /* Min width and height */ + 0, 0, /* Max width and height */ + 1, 1, /* Width and height increments */ + {0, 0}, {0, 0}, /* Aspect ratio - not used */ + 1, 1, /* base size */ + (NorthWestGravity) /* gravity */ }; Pixel GetColor(char *name); @@ -88,7 +85,7 @@ XGCValues gcv; GC myGC; int My_XNextEvent(Display *dpy, XEvent *event); void DrawWindow(int mode); -void paste_primary(int window,int property,int Delete); +void paste_primary(int window, int property, int Delete); void request_selection(int time); /*********************************************************************** @@ -97,124 +94,120 @@ void request_selection(int time); * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - XWMHints wm_hints; - XClassHint class_hints; - XTextProperty window_name; - - /* Save the program name - its used for error messages and option parsing */ - temp = argv[0]; - - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - - if((argc != 6)&&(argc != 7)) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - /* Dead pipes mean fvwm died */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - /* Initialize X connection */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - x_fd = XConnectionNumber(dpy); - - screen= DefaultScreen(dpy); - Root = RootWindow(dpy, screen); - if(Root == None) - { - fprintf(stderr,"%s: Screen %d is not valid ", MyName, (int)screen); - exit(1); - } - d_depth = DefaultDepth(dpy, screen); - - fd_width = GetFdWidth(); - - wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); - - /* load the font */ - if ((font = XLoadQueryFont(dpy, font_string)) == NULL) - { - if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) - { - fprintf(stderr,"%s: No fonts available\n",MyName); - exit(1); + char *temp, *s; + XWMHints wm_hints; + XClassHint class_hints; + XTextProperty window_name; + + /* Save the program name - its used for error messages and option + * parsing */ + temp = argv[0]; + + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + size_t name_len = strlen(temp); + MyName = xmalloc(name_len + 2); + strlcpy(MyName, "*", name_len + 2); + strlcat(MyName, temp, name_len + 2); + + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); } - }; - - - fore_pix = GetColor(ForeColor); - back_pix = GetColor(BackColor); - - valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); - attributes.background_pixel = back_pix; - attributes.border_pixel = fore_pix; - attributes.event_mask = KeyPressMask | ExposureMask | ButtonPressMask; - - sizehints.width = 8*XTextWidth(font,"MMMMMMMMMM",10); - sizehints.height = 3*(font->ascent+font->descent+2)+2; - sizehints.x = 0; - sizehints.y = 0; - sizehints.width_inc = 0.1*XTextWidth(font,"MMMMMMMMMM",10); - sizehints.height_inc = 3*(font->ascent+font->descent+2)+2; - sizehints.base_width = 1; - sizehints.base_height = 3*(font->ascent+font->descent+2)+2; - sizehints.min_width = 1; - sizehints.min_height = 3*(font->ascent+font->descent+2)+2; - sizehints.max_height = 3*(font->ascent+font->descent+2)+2; - sizehints.max_width = 26*XTextWidth(font,"MMMMMMMMMM",10); - - window = XCreateWindow (dpy, Root, 0, 0, sizehints.width,sizehints.height, - (unsigned int) 1, - CopyFromParent, InputOutput, - (Visual *) CopyFromParent, - valuemask, &attributes); - - class_hints.res_name = "FvwmTalk"; - class_hints.res_class = "FvwmTalk"; - - wm_hints.flags = InputHint; - wm_hints.input = True;; - - XSetWMProtocols(dpy,window,&wm_del_win,1); - XSetWMNormalHints(dpy,window,&sizehints); - /* XStringListToTextProperty(&(argv[0]), 1, &window_name); */ - XStringListToTextProperty(&temp, 1, &window_name); - XSetWMProperties(dpy, window, &window_name, &window_name, - argv, argc, &sizehints, &wm_hints, &class_hints); - - gcv.foreground = fore_pix; - gcv.background = back_pix; - gcv.font = font->fid; - myGC = XCreateGC(dpy,window,GCForeground|GCBackground|GCFont,&gcv); - - - previous_line[0] = 0; - last_error[0] = 0; - XMapWindow(dpy,window); - Loop(fd); - return 0; -} + /* Dead pipes mean fvwm died */ + signal(SIGPIPE, DeadPipe); + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + /* Initialize X connection */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + x_fd = XConnectionNumber(dpy); + + screen = DefaultScreen(dpy); + Root = RootWindow(dpy, screen); + if (Root == None) { + fprintf( + stderr, "%s: Screen %d is not valid ", MyName, (int)screen); + exit(1); + } + d_depth = DefaultDepth(dpy, screen); + + fd_width = GetFdWidth(); + + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + + /* load the font */ + if ((font = XLoadQueryFont(dpy, font_string)) == NULL) { + if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) { + fprintf(stderr, "%s: No fonts available\n", MyName); + exit(1); + } + } + + fore_pix = GetColor(ForeColor); + back_pix = GetColor(BackColor); + + valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); + attributes.background_pixel = back_pix; + attributes.border_pixel = fore_pix; + attributes.event_mask = KeyPressMask | ExposureMask | ButtonPressMask; + + sizehints.width = 8 * XTextWidth(font, "MMMMMMMMMM", 10); + sizehints.height = 3 * (font->ascent + font->descent + 2) + 2; + sizehints.x = 0; + sizehints.y = 0; + sizehints.width_inc = 0.1 * XTextWidth(font, "MMMMMMMMMM", 10); + sizehints.height_inc = 3 * (font->ascent + font->descent + 2) + 2; + sizehints.base_width = 1; + sizehints.base_height = 3 * (font->ascent + font->descent + 2) + 2; + sizehints.min_width = 1; + sizehints.min_height = 3 * (font->ascent + font->descent + 2) + 2; + sizehints.max_height = 3 * (font->ascent + font->descent + 2) + 2; + sizehints.max_width = 26 * XTextWidth(font, "MMMMMMMMMM", 10); + + window = XCreateWindow(dpy, Root, 0, 0, sizehints.width, + sizehints.height, (unsigned int)1, CopyFromParent, InputOutput, + (Visual *)CopyFromParent, valuemask, &attributes); + + class_hints.res_name = "FvwmTalk"; + class_hints.res_class = "FvwmTalk"; + + wm_hints.flags = InputHint; + wm_hints.input = True; + ; + + XSetWMProtocols(dpy, window, &wm_del_win, 1); + XSetWMNormalHints(dpy, window, &sizehints); + /* XStringListToTextProperty(&(argv[0]), 1, &window_name); */ + XStringListToTextProperty(&temp, 1, &window_name); + XSetWMProperties(dpy, window, &window_name, &window_name, argv, argc, + &sizehints, &wm_hints, &class_hints); + + gcv.foreground = fore_pix; + gcv.background = back_pix; + gcv.font = font->fid; + myGC = + XCreateGC(dpy, window, GCForeground | GCBackground | GCFont, &gcv); + + previous_line[0] = 0; + last_error[0] = 0; + XMapWindow(dpy, window); + Loop(fd); + return 0; +} /*********************************************************************** * @@ -222,260 +215,244 @@ int main(int argc, char **argv) * Loop - wait for data to process * ***********************************************************************/ -void Loop(int *fd) +void +Loop(int *fd) { - KeySym keysym; - static XComposeStatus compose = {NULL,0}; - XEvent event; - char kbuf[100]; - int count; - - pos = 0; - Text[0] = 0; - - while(1) - { - if(My_XNextEvent(dpy, &event)) - { - switch(event.type) - { - case KeyPress: - count = XLookupString(&(event.xkey),kbuf,99,&keysym,&compose); - kbuf[count] = (unsigned char)0; - if((keysym == XK_BackSpace )||(keysym == XK_Delete)) - { - if(pos > 0) - Text[--pos] = 0; - } - else if((keysym == XK_Return)||(keysym == XK_KP_Enter)) - { - SendText(fd,Text,0); - last_error[0] = 0; - strncpy(previous_line,Text,255); - previous_line[255] = 0; - pos = 0; - Text[pos] = 0; - DrawWindow(ALL); + KeySym keysym; + static XComposeStatus compose = {NULL, 0}; + XEvent event; + char kbuf[100]; + int count; + + pos = 0; + Text[0] = 0; + + sandbox_x11_only("FvwmTalk"); + sandbox_x11_only("FvwmTalk"); + + while (1) { + if (My_XNextEvent(dpy, &event)) { + switch (event.type) { + case KeyPress: + count = XLookupString( + &(event.xkey), kbuf, 99, &keysym, &compose); + kbuf[count] = (unsigned char)0; + if ((keysym == XK_BackSpace) || + (keysym == XK_Delete)) { + if (pos > 0) + Text[--pos] = 0; + } else if ((keysym == XK_Return) || + (keysym == XK_KP_Enter)) { + SendText(fd, Text, 0); + last_error[0] = 0; + strncpy(previous_line, Text, 255); + previous_line[255] = 0; + pos = 0; + Text[pos] = 0; + DrawWindow(ALL); + } else { + if (pos + count < 255) { + strlcat( + Text, kbuf, sizeof(Text)); + pos += count; + } else + XBell(dpy, 0); + } + DrawWindow(UPDATE_ONLY); + break; + case ButtonPress: + if (event.xbutton.button == 2) + request_selection(event.xbutton.time); + break; + case Expose: + DrawWindow(ALL); + break; + case ClientMessage: + if ((event.xclient.format == 32) && + (event.xclient.data.l[0] == wm_del_win)) { + exit(0); + } + break; + case SelectionNotify: + paste_primary(event.xselection.requestor, + event.xselection.property, True); + default: + break; + } } - else - { - if(pos + count < 255) - { - strcat(Text,kbuf); - pos += count; - } - else - XBell(dpy,0); - } - DrawWindow(UPDATE_ONLY); - break; - case ButtonPress: - if(event.xbutton.button == 2) - request_selection(event.xbutton.time); - break; - case Expose: - DrawWindow(ALL); - break; - case ClientMessage: - if ((event.xclient.format==32) && - (event.xclient.data.l[0]==wm_del_win)) - { - exit(0); - } - break; - case SelectionNotify: - paste_primary(event.xselection.requestor, - event.xselection.property,True); - default: - break; - } } - } } - /*********************************************************************** * * Procedure: * SIGPIPE handler - SIGPIPE means fvwm is dying * ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - fprintf(stderr,"FvwmTalk: dead pipe\n"); - exit(0); + fprintf(stderr, "FvwmTalk: dead pipe\n"); + exit(0); } - - /**************************************************************************** * * Loads a single color * ****************************************************************************/ -Pixel GetColor(char *name) +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(dpy, Root,&attributes); - color.pixel = 0; - if (!XParseColor (dpy, attributes.colormap, name, &color)) - { - nocolor("parse",name); - } - else if(!XAllocColor (dpy, attributes.colormap, &color)) - { - nocolor("alloc",name); - } - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(dpy, Root, &attributes); + color.pixel = 0; + if (!XParseColor(dpy, attributes.colormap, name, &color)) { + nocolor("parse", name); + } else if (!XAllocColor(dpy, attributes.colormap, &color)) { + nocolor("alloc", name); + } + return color.pixel; } - -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"%s: can't %s %s\n", MyName, a,b); - + fprintf(stderr, "%s: can't %s %s\n", MyName, a, b); } - /*************************************************************************** * * 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) { - fd_set in_fdset; - unsigned long header[HEADER_SIZE]; - int count; - static int miss_counter = 0; - unsigned long *body; - - if(XPending(dpy)) - { - XNextEvent(dpy,event); - return 1; - } - - FD_ZERO(&in_fdset); - FD_SET(x_fd,&in_fdset); - FD_SET(fd[1],&in_fdset); - - select(fd_width,SELECT_TYPE_ARG234 &in_fdset, 0, 0, NULL); - - if(FD_ISSET(x_fd, &in_fdset)) - { - if(XPending(dpy)) - { - XNextEvent(dpy,event); - miss_counter = 0; - return 1; + fd_set in_fdset; + unsigned long header[HEADER_SIZE]; + int count; + static int miss_counter = 0; + unsigned long *body; + + if (XPending(dpy)) { + XNextEvent(dpy, event); + return 1; } - else - miss_counter++; - if(miss_counter > 100) - DeadPipe(0); - } - - if(FD_ISSET(fd[1], &in_fdset)) - { - if((count = ReadFvwmPacket(fd[1],header,&body)) > 0) - { - if(header[1] == M_ERROR || header[1] == M_STRING) - { - strncpy(last_error,(char *)(&body[3]),255); - /*last_error[strlen(last_error)-1] = 0;*/ - last_error[strlen(last_error)] = 0; - last_error[255] = 0; - XClearArea(dpy,window,0,0,10000,10000,1); - } - - free(body); - } - } - return 0; -} + FD_ZERO(&in_fdset); + FD_SET(x_fd, &in_fdset); + FD_SET(fd[1], &in_fdset); + + select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL); + + if (FD_ISSET(x_fd, &in_fdset)) { + if (XPending(dpy)) { + XNextEvent(dpy, event); + miss_counter = 0; + return 1; + } else + miss_counter++; + if (miss_counter > 100) + DeadPipe(0); + } + if (FD_ISSET(fd[1], &in_fdset)) { + if ((count = ReadFvwmPacket(fd[1], header, &body)) > 0) { + if (header[1] == M_ERROR || header[1] == M_STRING) { + strncpy(last_error, (char *)(&body[3]), 255); + /*last_error[strlen(last_error)-1] = 0;*/ + last_error[strlen(last_error)] = 0; + last_error[255] = 0; + XClearArea(dpy, window, 0, 0, 10000, 10000, 1); + } + + free(body); + } + } + return 0; +} -void request_selection(int time) +void +request_selection(int time) { - Atom sel_property; - - if (XGetSelectionOwner(dpy,XA_PRIMARY) == None) - { - /* No primary selection so use the cut buffer. - */ - paste_primary(DefaultRootWindow(dpy),XA_CUT_BUFFER0,False); - return; - } - sel_property = XInternAtom(dpy,"VT_SELECTION",False); - XConvertSelection(dpy,XA_PRIMARY,XA_STRING,sel_property,window,time); + Atom sel_property; + + if (XGetSelectionOwner(dpy, XA_PRIMARY) == None) { + /* No primary selection so use the cut buffer. */ + paste_primary(DefaultRootWindow(dpy), XA_CUT_BUFFER0, False); + return; + } + sel_property = XInternAtom(dpy, "VT_SELECTION", False); + XConvertSelection( + dpy, XA_PRIMARY, XA_STRING, sel_property, window, time); } -void paste_primary(int window,int property,int Delete) +void +paste_primary(int window, int property, int Delete) { - Atom actual_type; - int actual_format,i; - unsigned long nitems, bytes_after, nread; - unsigned char *data, *data2; - - if (property == None) - return; - - nread = 0; - do - { - if (XGetWindowProperty(dpy,window,property,nread/4,PROP_SIZE,Delete, - AnyPropertyType,&actual_type,&actual_format, - &nitems,&bytes_after,(unsigned char **)&data) - != Success) - return; - if (actual_type != XA_STRING) - return; - - data2 = data; - /* want to make a \n to \r mapping for cut and paste only */ - for(i=0;i 0) - { - strncat(Text,(char *)data2,255-pos-nitems); - pos = strlen(Text); - DrawWindow(UPDATE_ONLY); - } - nread += nitems; - XFree(data2); - } while (bytes_after > 0); + Atom actual_type; + int actual_format, i; + unsigned long nitems, bytes_after, nread; + unsigned char *data, *data2; + + if (property == None) + return; + + nread = 0; + do { + if (XGetWindowProperty(dpy, window, property, nread / 4, + PROP_SIZE, Delete, AnyPropertyType, &actual_type, + &actual_format, &nitems, &bytes_after, + (unsigned char **)&data) != Success) + return; + if (actual_type != XA_STRING) + return; + + data2 = data; + /* want to make a \n to \r mapping for cut and paste only */ + for (i = 0; i < nitems; i++) { + if (*data == '\n') + *data = '\r'; + data++; + } + + if (255 - pos > 0) { + if (pos + (int)nitems < 255) + strncat(Text, (char *)data2, + 255 - pos - (int)nitems); + pos = strlen(Text); + DrawWindow(UPDATE_ONLY); + } + nread += nitems; + XFree(data2); + } while (bytes_after > 0); } -void DrawWindow(int mode) +void +DrawWindow(int mode) { - int w; - - if(mode == ALL) - { - XClearWindow(dpy,window); - XDrawImageString(dpy,window,myGC,2,(font->ascent+font->descent+2)+ - font->ascent+2,last_error,strlen(last_error)); - XDrawImageString(dpy,window,myGC,2, font->ascent+2, - previous_line,strlen(previous_line)); - } - else - { - XClearArea(dpy,window,0, - 2*(font->ascent+font->descent+2),10000,10000,0); - } - XDrawImageString(dpy,window,myGC,2,2*(font->ascent+font->descent+2)+ - font->ascent+2,Text,pos); - w=XTextWidth(font,Text,pos); - XDrawLine(dpy,window,myGC,4+w,2*(font->ascent+font->descent+2)+2, - 4+w,2*(font->ascent+font->descent+2)+ - font->ascent+font->descent); + int w; + + if (mode == ALL) { + XClearWindow(dpy, window); + XDrawImageString(dpy, window, myGC, 2, + (font->ascent + font->descent + 2) + font->ascent + 2, + last_error, strlen(last_error)); + XDrawImageString(dpy, window, myGC, 2, font->ascent + 2, + previous_line, strlen(previous_line)); + } else { + XClearArea(dpy, window, 0, + 2 * (font->ascent + font->descent + 2), 10000, 10000, 0); + } + XDrawImageString(dpy, window, myGC, 2, + 2 * (font->ascent + font->descent + 2) + font->ascent + 2, Text, + pos); + w = XTextWidth(font, Text, pos); + XDrawLine(dpy, window, myGC, 4 + w, + 2 * (font->ascent + font->descent + 2) + 2, 4 + w, + 2 * (font->ascent + font->descent + 2) + font->ascent + + font->descent); } Index: fvwm/modules/FvwmTalk/FvwmTalk.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmTalk/FvwmTalk.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmTalk/FvwmTalk.h --- fvwm/modules/FvwmTalk/FvwmTalk.h +++ fvwm/modules/FvwmTalk/FvwmTalk.h @@ -1,30 +1,27 @@ -#include "fvwmlib.h" +#include "fvwmlib.h" #define ACTION1 1 #define ACTION2 2 #define ACTION3 4 -struct list -{ - unsigned long id; - unsigned long last_focus_time; - unsigned long actions; - struct list *next; +struct list { + unsigned long id; + unsigned long last_focus_time; + unsigned long actions; + struct list *next; }; /************************************************************************* * * Subroutine Prototypes - * + * *************************************************************************/ void Loop(int *fd); -void SendInfo(int *fd,char *message,unsigned long window); -char *safemalloc(int length); +void SendInfo(int *fd, char *message, unsigned long window); struct list *find_window(unsigned long id); void remove_window(unsigned long id); void add_window(unsigned long new_win); void update_focus(struct list *l, unsigned long); void DeadPipe(int nonsense); void find_next_event_time(void); -void process_message(unsigned long type,unsigned long *body); - +void process_message(unsigned long type, unsigned long *body); Index: fvwm/modules/FvwmWinList/ButtonArray.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/ButtonArray.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/ButtonArray.c --- fvwm/modules/FvwmWinList/ButtonArray.c +++ fvwm/modules/FvwmWinList/ButtonArray.c @@ -9,34 +9,29 @@ * whatsoever. Use this program at your own risk. Permission to use this * program for any purpose is given, as long as the copyright is kept intact. * - * Things to do: Convert to C++ (In Progress) */ -#include "config.h" +#include "ButtonArray.h" -#include -#include #include #include +#include +#include #include "../../libs/fvwmlib.h" - #include "FvwmWinList.h" -#include "ButtonArray.h" -#include "Mallocs.h" - +#include "config.h" extern XFontStruct *ButtonFont; extern Display *dpy; extern Window win; -extern GC shadow[MAX_COLOUR_SETS],hilite[MAX_COLOUR_SETS]; -extern GC graph[MAX_COLOUR_SETS],background[MAX_COLOUR_SETS]; +extern GC shadow[MAX_COLOUR_SETS], hilite[MAX_COLOUR_SETS]; +extern GC graph[MAX_COLOUR_SETS], background[MAX_COLOUR_SETS]; extern int LeftJustify, TruncateLeft, ShowFocus; extern long CurrentDesk; extern int ShowCurrentDesk; - /************************************************************************* * * * Button handling functions and procedures * @@ -46,457 +41,454 @@ extern int ShowCurrentDesk; /* ------------------------------------------------------------------------- ButtonNew - Allocates and fills a new button structure ------------------------------------------------------------------------- */ -Button *ButtonNew(char *title, FvwmPicture *p, int up) +Button * +ButtonNew(char *title, FvwmPicture *p, int up) { - Button *new; - - new = (Button *)safemalloc(sizeof(Button)); - new->title = safemalloc(strlen(title)+1); - strcpy(new->title, title); - if (p != NULL) - { - new->p.picture = p->picture; - new->p.mask = p->mask; - new->p.width = p->width; - new->p.height = p->height; - new->p.depth = p->depth; - } - else - - new->p.picture = 0; - - new->up = up; - new->next = NULL; - new->needsupdate = 1; - - return new; + Button *new; + + new = (Button *)xmalloc(sizeof(Button)); + size_t title_len = strlen(title); + new->title = xmalloc(title_len + 1); + strlcpy(new->title, title, title_len + 1); + if (p != NULL) { + new->p.picture = p->picture; + new->p.mask = p->mask; + new->p.width = p->width; + new->p.height = p->height; + new->p.depth = p->depth; + } else + + new->p.picture = 0; + + new->up = up; + new->next = NULL; + new->needsupdate = 1; + + return new; } /****************************************************************************** InitArray - Initialize the arrary of buttons ******************************************************************************/ -void InitArray(ButtonArray *array,int x,int y,int w,int h) +void +InitArray(ButtonArray *array, int x, int y, int w, int h) { - array->count=0; - array->head=array->tail=NULL; - array->x=x; - array->y=y; - array->w=w; - array->h=h; + array->count = 0; + array->head = array->tail = NULL; + array->x = x; + array->y = y; + array->w = w; + array->h = h; } /****************************************************************************** UpdateArray - Update the array specifics. x,y, width, height ******************************************************************************/ -void UpdateArray(ButtonArray *array,int x,int y,int w, int h) +void +UpdateArray(ButtonArray *array, int x, int y, int w, int h) { - Button *temp; - - if (x!=-1) array->x=x; - if (y!=-1) array->y=y; - if (w!=-1) array->w=w; - if (h!=-1) array->h=h; - for(temp=array->head;temp!=NULL;temp=temp->next) temp->needsupdate=1; + Button *temp; + + if (x != -1) + array->x = x; + if (y != -1) + array->y = y; + if (w != -1) + array->w = w; + if (h != -1) + array->h = h; + for (temp = array->head; temp != NULL; temp = temp->next) + temp->needsupdate = 1; } /****************************************************************************** AddButton - Allocate space for and add the button to the bottom ******************************************************************************/ -int AddButton(ButtonArray *array, char *title, FvwmPicture *p, int up) +int +AddButton(ButtonArray *array, char *title, FvwmPicture *p, int up) { - Button *new; - - new = ButtonNew(title, p, up); - if (array->head == NULL) - { - array->head = array->tail = new; - } - else - { - array->tail->next = new; - array->tail = new; - } - array->count++; - -/* in Taskbar this replaces below ArrangeButtonArray (array); -*/ - - new->tw=XTextWidth(ButtonFont,title,strlen(title)); - new->truncatewidth=0; - new->next=NULL; - new->needsupdate=1; - new->set=0; - - return (array->count-1); + Button *new; + + new = ButtonNew(title, p, up); + if (array->head == NULL) { + array->head = array->tail = new; + } else { + array->tail->next = new; + array->tail = new; + } + array->count++; + + /* in Taskbar this replaces below ArrangeButtonArray (array); + */ + + new->tw = XTextWidth(ButtonFont, title, strlen(title)); + new->truncatewidth = 0; + new->next = NULL; + new->needsupdate = 1; + new->set = 0; + + return (array->count - 1); } /****************************************************************************** UpdateButton - Change the name/stae of a button ******************************************************************************/ -int UpdateButton(ButtonArray *array, int butnum, char *title, int up) +int +UpdateButton(ButtonArray *array, int butnum, char *title, int up) { - Button *temp; - - temp=find_n(array,butnum); - if (temp!=NULL) - { - if (title!=NULL) - { - temp->title=(char *)saferealloc(temp->title,strlen(title)+1); - strcpy(temp->title,title); - temp->tw=XTextWidth(ButtonFont,title,strlen(title)); - temp->truncatewidth = 0; - } - if (up!=-1) temp->up=up; - } else return -1; - temp->needsupdate=1; - return 1; + Button *temp; + + temp = find_n(array, butnum); + if (temp != NULL) { + if (title != NULL) { + size_t title_len = strlen(title); + temp->title = + (char *)xrealloc(temp->title, title_len + 1); + strlcpy(temp->title, title, title_len + 1); + temp->tw = XTextWidth(ButtonFont, title, strlen(title)); + temp->truncatewidth = 0; + } + if (up != -1) + temp->up = up; + } else + return -1; + temp->needsupdate = 1; + return 1; } /* ------------------------------------------------------------------------- UpdateButtonPicture - Change the picture of a button ------------------------------------------------------------------------- */ -int UpdateButtonPicture(ButtonArray *array, int butnum, FvwmPicture *p) +int +UpdateButtonPicture(ButtonArray *array, int butnum, FvwmPicture *p) { - Button *temp; - temp=find_n(array,butnum); - if (temp == NULL) return -1; - if (temp->p.picture != p->picture || temp->p.mask != p->mask) - { - temp->p.picture = p->picture; - temp->p.mask = p->mask; - temp->p.width = p->width; - temp->p.height = p->height; - temp->p.depth = p->depth; - temp->needsupdate = 1; - } - return 1; + Button *temp; + temp = find_n(array, butnum); + if (temp == NULL) + return -1; + if (temp->p.picture != p->picture || temp->p.mask != p->mask) { + temp->p.picture = p->picture; + temp->p.mask = p->mask; + temp->p.width = p->width; + temp->p.height = p->height; + temp->p.depth = p->depth; + temp->needsupdate = 1; + } + return 1; } /****************************************************************************** UpdateButtonSet - Change colour set of a button between odd and even ******************************************************************************/ -int UpdateButtonSet(ButtonArray *array, int butnum, int set) +int +UpdateButtonSet(ButtonArray *array, int butnum, int set) { - Button *btn; - - btn=find_n(array, butnum); - if (btn != NULL) - { - if ((btn->set & 1) != set) - { - btn->set = (btn->set & 2) | set; - btn->needsupdate = 1; - } - } else return -1; - return 1; + Button *btn; + + btn = find_n(array, butnum); + if (btn != NULL) { + if ((btn->set & 1) != set) { + btn->set = (btn->set & 2) | set; + btn->needsupdate = 1; + } + } else + return -1; + return 1; } /****************************************************************************** UpdateButtonDesk - Change desk of a button ******************************************************************************/ -int UpdateButtonDesk(ButtonArray *array, int butnum, long desk ) +int +UpdateButtonDesk(ButtonArray *array, int butnum, long desk) { - Button *btn; - - btn = find_n(array, butnum); - if (btn != NULL) - { - btn->desk = desk; - } else return -1; - return 1; + Button *btn; + + btn = find_n(array, butnum); + if (btn != NULL) { + btn->desk = desk; + } else + return -1; + return 1; } - /****************************************************************************** RemoveButton - Delete a button from the list ******************************************************************************/ -void RemoveButton(ButtonArray *array, int butnum) +void +RemoveButton(ButtonArray *array, int butnum) { - Button *temp,*temp2; - - if (butnum==0) - { - temp2=array->head; - temp=array->head=array->head->next; - } - else - { - temp=find_n(array,butnum-1); - if (temp==NULL) return; - temp2=temp->next; - temp->next=temp2->next; - } - - if (array->tail==temp2) array->tail=temp; - - FreeButton(temp2); - - if (temp!=array->head) temp=temp->next; - for(;temp!=NULL;temp=temp->next) temp->needsupdate=1; + Button *temp, *temp2; + + if (butnum == 0) { + temp2 = array->head; + temp = array->head = array->head->next; + } else { + temp = find_n(array, butnum - 1); + if (temp == NULL) + return; + temp2 = temp->next; + temp->next = temp2->next; + } + + if (array->tail == temp2) + array->tail = temp; + + FreeButton(temp2); + + if (temp != array->head) + temp = temp->next; + for (; temp != NULL; temp = temp->next) + temp->needsupdate = 1; } /****************************************************************************** find_n - Find the nth button in the list (Use internally) ******************************************************************************/ -Button *find_n(ButtonArray *array, int n) +Button * +find_n(ButtonArray *array, int n) { - Button *temp; - int i; + Button *temp; + int i; - temp=array->head; - for(i=0;inext); - return temp; + temp = array->head; + for (i = 0; i < n && temp != NULL; i++, temp = temp->next) + ; + return temp; } /****************************************************************************** FreeButton - Free space allocated to a button ******************************************************************************/ -void FreeButton(Button *ptr) +void +FreeButton(Button *ptr) { - if (ptr != NULL) { - if (ptr->title!=NULL) free(ptr->title); - free(ptr); - } + if (ptr != NULL) { + if (ptr->title != NULL) + free(ptr->title); + free(ptr); + } } /****************************************************************************** FreeAllButtons - Free the whole array of buttons ******************************************************************************/ -void FreeAllButtons(ButtonArray *array) +void +FreeAllButtons(ButtonArray *array) { -Button *temp,*temp2; - for(temp=array->head;temp!=NULL;) - { - temp2=temp; - temp=temp->next; - FreeButton(temp2); - } + Button *temp, *temp2; + for (temp = array->head; temp != NULL;) { + temp2 = temp; + temp = temp->next; + FreeButton(temp2); + } } /****************************************************************************** DoButton - Draw the specified button. (Used internally) ******************************************************************************/ -void DoButton(Button *button, int x, int y, int w, int h) +void +DoButton(Button *button, int x, int y, int w, int h) { - int up,Fontheight,newx,set; - GC topgc; - GC bottomgc; - char *string; - XGCValues gcv; - unsigned long gcm; - XFontStruct *font; - - up=button->up; - set=button->set; - topgc = up ? hilite[set] : shadow[set]; - bottomgc = up ? shadow[set] : hilite[set]; - font = ButtonFont; - - gcm = GCFont; - gcv.font = font->fid; - XChangeGC(dpy, graph[set], gcm, &gcv); - - - Fontheight=ButtonFont->ascent+ButtonFont->descent; - - /*? XClearArea(dpy,win,x,y,w,h,False);*/ - XFillRectangle(dpy,win,background[set],x,y,w,h+1); - - if ((button->p.picture != 0)/* && + int up, Fontheight, newx, set; + GC topgc; + GC bottomgc; + char *string; + XGCValues gcv; + unsigned long gcm; + XFontStruct *font; + + up = button->up; + set = button->set; + topgc = up ? hilite[set] : shadow[set]; + bottomgc = up ? shadow[set] : hilite[set]; + font = ButtonFont; + + gcm = GCFont; + gcv.font = font->fid; + XChangeGC(dpy, graph[set], gcm, &gcv); + + Fontheight = ButtonFont->ascent + ButtonFont->descent; + + /*? XClearArea(dpy,win,x,y,w,h,False);*/ + XFillRectangle(dpy, win, background[set], x, y, w, h + 1); + + if ((button->p.picture != 0)/* && (w + button->p.width + w3p + 3 > MIN_BUTTON_SIZE)*/) { - - gcm = GCClipMask|GCClipXOrigin|GCClipYOrigin; - gcv.clip_mask = button->p.mask; - gcv.clip_x_origin = x + 4; - gcv.clip_y_origin = y + ((h-button->p.height) >> 1); - XChangeGC(dpy, hilite[set], gcm, &gcv); - XCopyArea(dpy, button->p.picture, win, hilite[set], 0, 0, - button->p.width, button->p.height, - gcv.clip_x_origin, gcv.clip_y_origin); - gcm = GCClipMask; - gcv.clip_mask = None; - XChangeGC(dpy, hilite[set], gcm, &gcv); - - newx = button->p.width+6; - } - else - { - if (LeftJustify) - newx=4; - else - newx=max((w-button->tw)/2,4); - } - - string=button->title; - - if (!LeftJustify) { - if (TruncateLeft && (w-button->tw)/2 < 4) { - if (button->truncatewidth == w) - string=button->truncate_title; - else { - string=button->title; - while(*string && (w-XTextWidth(ButtonFont,string,strlen(string)))/2 < 4) - string++; - button->truncatewidth = w; - button->truncate_title=string; - } - } - } - XDrawString(dpy,win,graph[set],x+newx,y+3+ButtonFont->ascent,string,strlen(string)); - button->needsupdate=0; - - /* Draw relief last, don't forget that XDrawLine doesn't do the last pixel */ - XDrawLine(dpy,win,topgc,x,y,x+w-1,y); - XDrawLine(dpy,win,topgc,x+1,y+1,x+w-2,y+1); - XDrawLine(dpy,win,topgc,x,y+1,x,y+h+1); - XDrawLine(dpy,win,topgc,x+1,y+2,x+1,y+h); - XDrawLine(dpy,win,bottomgc,x+1,y+h,x+w,y+h); - XDrawLine(dpy,win,bottomgc,x+2,y+h-1,x+w-1,y+h-1); - XDrawLine(dpy,win,bottomgc,x+w-1,y,x+w-1,y+h); - XDrawLine(dpy,win,bottomgc,x+w-2,y+1,x+w-2,y+h-1); - + gcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; + gcv.clip_mask = button->p.mask; + gcv.clip_x_origin = x + 4; + gcv.clip_y_origin = y + ((h - button->p.height) >> 1); + XChangeGC(dpy, hilite[set], gcm, &gcv); + XCopyArea(dpy, button->p.picture, win, hilite[set], 0, 0, + button->p.width, button->p.height, gcv.clip_x_origin, + gcv.clip_y_origin); + gcm = GCClipMask; + gcv.clip_mask = None; + XChangeGC(dpy, hilite[set], gcm, &gcv); + + newx = button->p.width + 6; + } else { + if (LeftJustify) + newx = 4; + else + newx = max((w - button->tw) / 2, 4); + } + + string = button->title; + + if (!LeftJustify) { + if (TruncateLeft && (w - button->tw) / 2 < 4) { + if (button->truncatewidth == w) + string = button->truncate_title; + else { + string = button->title; + while (*string && + (w - XTextWidth(ButtonFont, string, + strlen(string))) / + 2 < + 4) + string++; + button->truncatewidth = w; + button->truncate_title = string; + } + } + } + XDrawString(dpy, win, graph[set], x + newx, y + 3 + ButtonFont->ascent, + string, strlen(string)); + button->needsupdate = 0; + + /* Draw relief last, don't forget that XDrawLine doesn't do the last + * pixel */ + XDrawLine(dpy, win, topgc, x, y, x + w - 1, y); + XDrawLine(dpy, win, topgc, x + 1, y + 1, x + w - 2, y + 1); + XDrawLine(dpy, win, topgc, x, y + 1, x, y + h + 1); + XDrawLine(dpy, win, topgc, x + 1, y + 2, x + 1, y + h); + XDrawLine(dpy, win, bottomgc, x + 1, y + h, x + w, y + h); + XDrawLine(dpy, win, bottomgc, x + 2, y + h - 1, x + w - 1, y + h - 1); + XDrawLine(dpy, win, bottomgc, x + w - 1, y, x + w - 1, y + h); + XDrawLine(dpy, win, bottomgc, x + w - 2, y + 1, x + w - 2, y + h - 1); } /****************************************************************************** DrawButtonArray - Draw the whole array (all=1), or only those that need. ******************************************************************************/ -void DrawButtonArray(ButtonArray *barray, int all) +void +DrawButtonArray(ButtonArray *barray, int all) { - Button *btn; - int i = 0; /* buttons displayed */ - - for(btn = barray->head; btn != NULL; btn = btn->next) - { - if((!ShowCurrentDesk) || ( btn->desk == CurrentDesk ) ) - { - if (btn->needsupdate || all) - { - DoButton - ( - btn,barray->x, - barray->y+(i*(barray->h+1)), - barray->w,barray->h - ); - } - i++; - } - } + Button *btn; + int i = 0; /* buttons displayed */ + + for (btn = barray->head; btn != NULL; btn = btn->next) { + if ((!ShowCurrentDesk) || (btn->desk == CurrentDesk)) { + if (btn->needsupdate || all) { + DoButton(btn, barray->x, + barray->y + (i * (barray->h + 1)), + barray->w, barray->h); + } + i++; + } + } } /****************************************************************************** SwitchButton - Alternate the state of a button ******************************************************************************/ -void SwitchButton(ButtonArray *array, int butnum) +void +SwitchButton(ButtonArray *array, int butnum) { - Button *btn; + Button *btn; - btn = find_n(array, butnum); - btn->up =!btn->up; - btn->needsupdate=1; - DrawButtonArray(array, 0); + btn = find_n(array, butnum); + btn->up = !btn->up; + btn->needsupdate = 1; + DrawButtonArray(array, 0); } /* ------------------------------------------------------------------------- RadioButton - Enable button i and verify all others are disabled ------------------------------------------------------------------------- */ -void RadioButton(ButtonArray *array, int butnum) +void +RadioButton(ButtonArray *array, int butnum) { - Button *temp; - int i; - - for(temp=array->head,i=0; temp!=NULL; temp=temp->next,i++) - { - if (i == butnum) - { - if (ShowFocus && temp->up) - { - temp->up = 0; - temp->needsupdate=1; - } - if (!(temp->set & 2)) - { - temp->set |= 2; - temp->needsupdate=1; - } - } - else - { - if (ShowFocus && !temp->up) - { - temp->up = 1; - temp->needsupdate = 1; - } - if (temp->set & 2) - { - temp->set &= 1; - temp->needsupdate = 1; - } - } - } + Button *temp; + int i; + + for (temp = array->head, i = 0; temp != NULL; temp = temp->next, i++) { + if (i == butnum) { + if (ShowFocus && temp->up) { + temp->up = 0; + temp->needsupdate = 1; + } + if (!(temp->set & 2)) { + temp->set |= 2; + temp->needsupdate = 1; + } + } else { + if (ShowFocus && !temp->up) { + temp->up = 1; + temp->needsupdate = 1; + } + if (temp->set & 2) { + temp->set &= 1; + temp->needsupdate = 1; + } + } + } } /****************************************************************************** WhichButton - Based on x,y which button was pressed ******************************************************************************/ -int WhichButton(ButtonArray *array,int x, int y) +int +WhichButton(ButtonArray *array, int x, int y) { - int num; - - num=y/(array->h+1); - if (xx || x>array->x+array->w || num<0 || num>array->count-1) num=-1; - - /* Current Desk Hack */ - - if(ShowCurrentDesk) - { - Button *temp; - int i, n; - - temp=array->head; - for(i=0, n = 0;n < (num + 1) && temp != NULL;temp=temp->next, i++) - { - if(temp->desk == CurrentDesk) - n++; - } - num = i-1; - } - return(num); + int num; + + num = y / (array->h + 1); + if (x < array->x || x > array->x + array->w || num < 0 || + num > array->count - 1) + num = -1; + + /* Current Desk Hack */ + + if (ShowCurrentDesk) { + Button *temp; + int i, n; + + temp = array->head; + for (i = 0, n = 0; n < (num + 1) && temp != NULL; + temp = temp->next, i++) { + if (temp->desk == CurrentDesk) + n++; + } + num = i - 1; + } + return (num); } /****************************************************************************** ButtonName - Return the name of the button ******************************************************************************/ -char *ButtonName(ButtonArray *array, int butnum) +char * +ButtonName(ButtonArray *array, int butnum) { - Button *temp; + Button *temp; - temp=find_n(array,butnum); - return temp->title; + temp = find_n(array, butnum); + return temp->title; } /****************************************************************************** PrintButtons - Print the array of button names to the console. (Debugging) ******************************************************************************/ -void PrintButtons(ButtonArray *array) +void +PrintButtons(ButtonArray *array) { - Button *temp; - - ConsoleMessage("List of Buttons:\n"); - for(temp=array->head;temp!=NULL;temp=temp->next) - ConsoleMessage(" %s is %s\n",temp->title,(temp->up) ? "Up":"Down"); -} + Button *temp; -#if 0 -/****************************************************************************** - ButtonArrayMaxWidth - Calculate the width needed for the widest title -******************************************************************************/ -int ButtonArrayMaxWidth(ButtonArray *array) -{ -Button *temp; -int x=0; - for(temp=array->head;temp!=NULL;temp=temp->next) - x=max(temp->tw,x); - return x; + ConsoleMessage("List of Buttons:\n"); + for (temp = array->head; temp != NULL; temp = temp->next) + ConsoleMessage( + " %s is %s\n", temp->title, (temp->up) ? "Up" : "Down"); } -#endif Index: fvwm/modules/FvwmWinList/ButtonArray.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/ButtonArray.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/ButtonArray.h --- fvwm/modules/FvwmWinList/ButtonArray.h +++ fvwm/modules/FvwmWinList/ButtonArray.h @@ -1,42 +1,44 @@ -/* FvwmWinList Module for Fvwm. +/* FvwmWinList Module for Fvwm. * * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or * Mike_Finger@atk.com) * * The functions in this header file that are the original work of Mike Finger. - * + * * No guarantees or warantees or anything are provided or implied in any way * whatsoever. Use this program at your own risk. Permission to use this * program for any purpose is given, as long as the copyright is kept intact. * - * Things to do: Convert to C++ (In Progress) */ +#ifndef BUTTONARRAY_H +#define BUTTONARRAY_H + +#include "../../libs/fvwmlib.h" + /* Struct definitions */ -typedef struct button -{ - char *title; - char *truncate_title; /* valid only if truncatewidth > 0 */ - int up, needsupdate, tw, set, truncatewidth; - struct button *next; - FvwmPicture p; - long desk; +typedef struct button { + char *title; + char *truncate_title; /* valid only if truncatewidth > 0 */ + int up, needsupdate, tw, set, truncatewidth; + struct button *next; + FvwmPicture p; + long desk; } Button; -typedef struct -{ - int count; - Button *head,*tail; - int x,y,w,h; +typedef struct { + int count; + Button *head, *tail; + int x, y, w, h; } ButtonArray; #define MAX_COLOUR_SETS 4 /* Function Prototypes */ Button *ButtonNew(char *title, FvwmPicture *p, int up); -void InitArray(ButtonArray *array,int x,int y,int w,int h); -void UpdateArray(ButtonArray *array,int x,int y,int w, int h); -int AddButton(ButtonArray *array, char *title, FvwmPicture *p,int up); +void InitArray(ButtonArray *array, int x, int y, int w, int h); +void UpdateArray(ButtonArray *array, int x, int y, int w, int h); +int AddButton(ButtonArray *array, char *title, FvwmPicture *p, int up); int UpdateButton(ButtonArray *array, int butnum, char *title, int up); int UpdateButtonPicture(ButtonArray *array, int butnum, FvwmPicture *p); int UpdateButtonSet(ButtonArray *array, int butnum, int set); @@ -47,7 +49,9 @@ void FreeButton(Button *ptr); void FreeAllButtons(ButtonArray *array); void DoButton(Button *ptr, int x, int y, int w, int h); void DrawButtonArray(ButtonArray *array, int all); -void SwitchButton(ButtonArray *array,int butnum); +void SwitchButton(ButtonArray *array, int butnum); void RadioButton(ButtonArray *array, int butnum); -int WhichButton(ButtonArray *array,int x, int y); +int WhichButton(ButtonArray *array, int x, int y); void PrintButtons(ButtonArray *array); + +#endif /* BUTTONARRAY_H */ Index: fvwm/modules/FvwmWinList/Colors.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/Colors.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/Colors.c --- fvwm/modules/FvwmWinList/Colors.c +++ fvwm/modules/FvwmWinList/Colors.c @@ -1,4 +1,4 @@ -/* Part of the FvwmWinList Module for Fvwm. +/* Part of the FvwmWinList Module for Fvwm. * * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or * Mike_Finger@atk.com) @@ -16,34 +16,36 @@ * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ -#include "config.h" -#include -#include #include "Colors.h" +#include +#include + +#include "config.h" extern Display *dpy; extern Window Root; /**************************************************************************** Loads a single color -*****************************************************************************/ -Pixel GetColor(char *name) +*****************************************************************************/ +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(dpy,Root,&attributes); - color.pixel = 0; - if (!XParseColor (dpy, attributes.colormap, name, &color)) - nocolor("parse",name); - else if(!XAllocColor (dpy, attributes.colormap, &color)) - nocolor("alloc",name); - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(dpy, Root, &attributes); + color.pixel = 0; + if (!XParseColor(dpy, attributes.colormap, name, &color)) + nocolor("parse", name); + else if (!XAllocColor(dpy, attributes.colormap, &color)) + nocolor("alloc", name); + return color.pixel; } - -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"FvwmWinList: can't %s %s\n", a,b); + fprintf(stderr, "FvwmWinList: can't %s %s\n", a, b); } Index: fvwm/modules/FvwmWinList/Colors.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/Colors.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/Colors.h --- fvwm/modules/FvwmWinList/Colors.h +++ fvwm/modules/FvwmWinList/Colors.h @@ -1,4 +1,4 @@ -/* Part of the FvwmWinList Module for Fvwm. +/* Part of the FvwmWinList Module for Fvwm. * * The functions in this header file were originally part of the GoodStuff * and FvwmIdent modules for Fvwm, so there copyrights are listed: @@ -16,4 +16,3 @@ Pixel GetColor(char *name); Pixel GetHilite(Pixel background); Pixel GetShadow(Pixel background); void nocolor(char *a, char *b); - Index: fvwm/modules/FvwmWinList/FvwmWinList.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/FvwmWinList.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/FvwmWinList.1 --- fvwm/modules/FvwmWinList/FvwmWinList.1 +++ fvwm/modules/FvwmWinList/FvwmWinList.1 @@ -1,139 +1,94 @@ .\" $OpenBSD: FvwmWinList.1,v 1.1.1.1 2006/11/26 10:53:55 matthieu Exp $ .\" t -.\" @(#)FvwmWinList.1 1995.5.27 -.TH FvwmWinList 1 "May 27th, 1995" 0.4h +.\" @(#)FvwmWinList.1 1995.5.27 +.TH FVWMWINLIST 1 "May 27, 1995" "0.4" "FVWM Modules" .UC .SH NAME FvwmWinList \- the FVWM window list module .SH SYNOPSIS FvwmWinList is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -The FvwmWinList module provides a window list made up of buttons, each -corresponding to a window that FVWM is managing. Clicking on the buttons -with any of the three mouse buttons will either do a default action or -can be user configured. Like the other modules, FvwmWinList only works -when fvwm is used as the window manager. - +FvwmWinList provides a window list composed of buttons, each corresponding to a +client managed by fvwm. Clicking any mouse button performs either the default +action or a user-configured command. Like other modules, FvwmWinList only works +when fvwm is the window manager. .SH COPYRIGHTS The FvwmWinList module is the original work of Mike Finger. - Copyright 1994, Mike Finger. The author makes no guarantees or warranties of -any kind about the use of this module. Use this modules at your own risk. -You may freely use this module or any portion of it for any purpose as long -as the copyright is kept intact. - +any kind about the use of this module. Use this module at your own risk. You +may freely use this module or any portion of it for any purpose as long as the +copyright is kept intact. .SH INITIALIZATION -During initialization, \fIFvwmWinList\fP will scan the same configuration file -that FVWM used during startup to find the options that pertain to it. These -options are discussed in a later section. - +During initialization, \fIFvwmWinList\fP scans the same configuration file that +fvwm reads at startup to locate its options. These options are discussed in a +later section. .SH INVOCATION -FvwmWinList can be invoked by fvwm during initialization by inserting the -line 'Module FvwmWinList' in the .fvwmrc file. - -FvwmWinList can also be bound to a keystroke, mouse button, or menu option to -be invoked later, in this case using 'Transient' as an argument will cause -FvwmWinList to resemble the built in window list. - -FvwmWinList must reside in a directory that is listed in the ModulePath option -of FVWM for it to be executed by FVWM. - +FvwmWinList can be launched during initialization by inserting the line `Module +FvwmWinList` in the .fvwmrc file. +It can also be bound to a keystroke, mouse button, or menu entry for later +invocation. Supplying the argument `Transient` makes FvwmWinList resemble the +built-in window list. +FvwmWinList must reside in a directory listed in fvwm's ModulePath option in +order to be executed. .SH CONFIGURATION OPTIONS -The following options can be placed in the .fvwmrc file - +Add the following directives to the .fvwmrc file to configure FvwmWinList. .IP "*FvwmWinListGeometry \fI{+-}{+-}\fP" -Specifies the location and gravity of the FvwmWinList window. At the current -time, size is not supported and FvwmWinList will resize itself as buttons are -added. If the NoAnchor option is not specified then the windows gravity -corner will be anchored, and the window will grow in the opposite direction. -(i.e. If the geometry is specified -5-5, that is SoutEastGravity. This will -cause the window to draw up and to the left as windows are added) - +Specify the location and gravity of the FvwmWinList window. Size is not +configurable; the window resizes as buttons are added. If NoAnchor is not set, +the gravity corner is anchored and the window grows in the opposite direction. +For example, `-5-5` selects SouthEastGravity so the window expands upward and to +the left as buttons appear. .IP "*FvwmWinListFont \fIfont\fP" -Specifies the font to be used for labeling the buttons. - +Specify the font used for button labels. .IP "*FvwmWinListFore \fIcolor\fP" -Specifies the color to use for the button names. - +Specify the color used for button labels. .IP "*FvwmWinListBack \fIcolor\fP" -Specifies the color for the buttons. - +Specify the background color of the buttons. .IP "*FvwmWinListFocusFore \fIcolor\fP" -Specifies the color to use for the button names for the window that -has the input focus. If omitted, the color from \fBFvwmWinListFore\fP -is used. - +Specify the label color for the button representing the window with input +focus. If omitted, \fBFvwmWinListFore\fP is used. .IP "*FvwmWinListFocusBack \fIcolor\fP" -Specifies the color to use for the button for the window that -has the input focus. If omitted, the color from \fBFvwmWinListBack\fP -is used. - +Specify the button color for the focused window. If omitted, +\fBFvwmWinListBack\fP is used. .IP "*FvwmWinListIconFore \fIcolor\fP" -Specifies the color to use for the button names for windows that -are iconified. If omitted, the color from \fBFvwmWinListFore\fP -is used. - +Specify the label color for iconified windows. If omitted, +\fBFvwmWinListFore\fP is used. .IP "*FvwmWinListIconBack \fIcolor\fP" -Specifies the color to use for the button for windows that -are iconified. If omitted, the color from \fBFvwmWinListBack\fP -is used. - +Specify the button color for iconified windows. If omitted, +\fBFvwmWinListBack\fP is used. .IP "*FvwmWinListDontDepressFocus" -By default FvwmWinlist will show the button for the window that has the -input focus as pressed in. This option disables that feature. - -.IP "*FvwmWinListUseSkipList -Tells FvwmWinList to not show the windows that are listed on a WindowListSkip -line if the configuration file. - -.IP "*FvwmWinListNoAnchor -By default, FvwmWinList will anchor the gravity corner so the window will grow -in the opposite direction. This undoes that option. - -.IP "*FvwmWinListUseIconNames -Tells FvwmWinList to use the icon name of the window instead of the full window -name. This is useful to keep the width of the window small. - -.IP "*FvwmWinListLeftJustify -By default, FvwmWinList will center the icon text in the icon. This option -causes it to be justified flush with the left edge of the icon. This option is -turned on when MiniIcons are used. - +Do not display the focused window's button as pressed. +.IP "*FvwmWinListUseSkipList" +Hide windows listed with the WindowListSkip style option. +.IP "*FvwmWinListNoAnchor" +Disable gravity anchoring so the window no longer grows away from the anchor +corner. +.IP "*FvwmWinListUseIconNames" +Display icon names instead of full window titles to keep the window narrow. +.IP "*FvwmWinListLeftJustify" +Left-justify label text instead of centering it. This option is enabled +automatically when MiniIcons are used. .IP "*FvwmWinListMinWidth \fIwidth\fP" .IP "*FvwmWinListMaxWidth \fIwidth\fP" -Specify the minimum and maximum widths that the buttons will shrink or grow -to. The buttons will normally size to fit the longest name, but certain -applications produce icon titles that can easily fill the screen. Setting -these parameters constrains the size of the buttons to be between the two -values. Setting them identically will fix the size of the buttons. -Setting Max < Min will have unpredictable results. - +Set the minimum and maximum button widths. Buttons normally size to the longest +name, but some applications produce extremely long titles. +These limits constrain the size range; identical values fix the width. +Using a maximum smaller than the minimum yields undefined results. .IP "*FvwmWinListTruncateLeft" -If names get truncated because of the setting of \fBFvwmWinListMaxWidth\fP, -they will normally get truncated on the right, so only the start of the names -are visible. Setting this resource will cause them to get truncated on the left, -so that the end of names are visible. This is useful when the window title -contains a directory and file name, for example. - -.IP "*FvwmWinListAction \fIaction response[,reponse...]\fP" -Tells FvwmWinList to do \fIresponse\fP when \fIaction\fP is done. The -currently supported \fIaction\fPs are: Click1, Click2, Click3. The currently -supported \fIresponse\fPs are any fvwm built-in commands, including modules -and functions. - +When titles are truncated because of \fBFvwmWinListMaxWidth\fP, remove +characters from the start rather than the end. +This is useful when titles contain directory paths or filenames. +.IP "*FvwmWinListAction \fIaction response[,response...]\fP" +Execute \fIresponse\fP when \fIaction\fP occurs. Supported actions are Click1, +Click2, and Click3. Responses may be any fvwm built-in commands, including +modules and functions. .SH SAMPLE CONFIGURATION -The following are excepts from a .fvwmrc file which describe FvwmWinList -initialization commands: - +The following snippets illustrate typical configuration commands: .nf -.sp -XCOMM####### -XCOMM Pop up the window list in tranient mode on button 3 press & hold - +XCOMM Pop up the window list in transient mode on button 3 press & hold Mouse 3 R A Module "FvwmWinList" FvwmWinList Transient -XCOMM######################### Window-Lister ############################### +XCOMM Window-Lister *FvwmWinListBack DarkOliveGreen *FvwmWinListFore PaleGoldenRod *FvwmWinListFont -*-new century schoolbook-bold-r-*-*-*-120-*-*-*-*-*-* @@ -147,12 +102,9 @@ XCOMM######################### Window-Lister ############################### *FvwmWinListMaxWidth 120 XCOMM I prefer the text centered XCOMM*FvwmWinListLeftJustify -XCOMM I like it achored +XCOMM I like it anchored XCOMM*FvwmWinListNoAnchor - -.sp .fi - .SH AUTHOR Mike Finger (mfinger@mermaid.micro.umn.edu) (Mike_Finger@atk.com) Index: fvwm/modules/FvwmWinList/FvwmWinList.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/FvwmWinList.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/FvwmWinList.c --- fvwm/modules/FvwmWinList/FvwmWinList.c +++ fvwm/modules/FvwmWinList/FvwmWinList.c @@ -21,14 +21,9 @@ * Modifications Done to Add Pixmaps, focus highlighting and Current Desk Only * By Don Mahurin, 1996, Some of this Code was taken from FvwmTaskBar - * Bug Notes:(Don Mahurin) - - * Moving a window doesnt send M_CONFIGURE, as I thought it should. Desktop - * for that button is not updated. - */ -#define TRUE 1 +#define TRUE 1 #define FALSE 0 #ifndef NO_CONSOLE @@ -36,48 +31,49 @@ #endif #define YES "Yes" -#define NO "No" +#define NO "No" -#include "config.h" +#include +#include -#include -#include #include -#include -#include -#include +#include #include +#include +#include + +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" #if HAVE_SYS_SELECT_H #include #endif -#include #include +#include -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include +#include +#include #include -#include #include -#include -#include +#include #include +#include #include "../../fvwm/module.h" - -#include "FvwmWinList.h" #include "ButtonArray.h" -#include "List.h" #include "Colors.h" -#include "Mallocs.h" +#include "FvwmWinList.h" +#include "List.h" -#define GRAB_EVENTS (ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|EnterWindowMask|LeaveWindowMask) +#define GRAB_EVENTS \ + (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | \ + EnterWindowMask | LeaveWindowMask) -#define SomeButtonDown(a) ((a)&Button1Mask||(a)&Button2Mask||(a)&Button3Mask) +#define SomeButtonDown(a) \ + ((a) & Button1Mask || (a) & Button2Mask || (a) & Button3Mask) /* File type information */ FILE *console; @@ -88,10 +84,10 @@ int x_fd; /* X related things */ Display *dpy; Window Root, win; -int screen,d_depth,ScreenWidth,ScreenHeight; +int screen, d_depth, ScreenWidth, ScreenHeight; Pixel back[MAX_COLOUR_SETS], fore[MAX_COLOUR_SETS]; -GC graph[MAX_COLOUR_SETS],shadow[MAX_COLOUR_SETS],hilite[MAX_COLOUR_SETS]; -GC background[MAX_COLOUR_SETS]; +GC graph[MAX_COLOUR_SETS], shadow[MAX_COLOUR_SETS], hilite[MAX_COLOUR_SETS]; +GC background[MAX_COLOUR_SETS]; XFontStruct *ButtonFont; int fontheight; static Atom wm_del_win; @@ -99,40 +95,42 @@ Atom MwmAtom = None; /* Module related information */ char *Module; -int WindowIsUp=0,win_width=5,win_height=5,win_grav,win_x,win_y,win_title,win_border; -int Clength,Transient=0,Pressed=0,ButPressed,Checked=0; -int MinWidth=DEFMINWIDTH,MaxWidth=DEFMAXWIDTH; +int WindowIsUp = 0, win_width = 5, win_height = 5, win_grav, win_x, win_y, + win_title, win_border; +int Clength, Transient = 0, Pressed = 0, ButPressed, Checked = 0; +int MinWidth = DEFMINWIDTH, MaxWidth = DEFMAXWIDTH; ButtonArray buttons; List windows; -char *ClickAction[3]={"Iconify -1,Raise","Iconify","Lower"},*EnterAction, - *BackColor[MAX_COLOUR_SETS] = { "white" }, - *ForeColor[MAX_COLOUR_SETS] = { "black" }, - *geometry=""; +char *ClickAction[3] = {"Iconify -1,Raise", "Iconify", "Lower"}, *EnterAction, + *BackColor[MAX_COLOUR_SETS] = {"white"}, + *ForeColor[MAX_COLOUR_SETS] = {"black"}, *geometry = ""; char *font_string = "fixed"; -int UseSkipList=0,Anchor=1,UseIconNames=0,LeftJustify=0,TruncateLeft=0,ShowFocus=1; +int UseSkipList = 0, Anchor = 1, UseIconNames = 0, LeftJustify = 0, + TruncateLeft = 0, ShowFocus = 1; long CurrentDesk = 0; int ShowCurrentDesk = 0; static volatile sig_atomic_t isTerminated = False; -static RETSIGTYPE TerminateHandler(int sig); +static void TerminateHandler(int sig); /*************************************************************************** * TerminateHandler - reentrant signal handler that ends the main event loop ***************************************************************************/ -static RETSIGTYPE TerminateHandler(int sig) +static void +TerminateHandler(int sig) { - isTerminated = True; + isTerminated = True; } -int ItemCountD(List *list ) +int +ItemCountD(List *list) { - if(!ShowCurrentDesk) + if (!ShowCurrentDesk) return ItemCount(list); /* else */ return ItemCountDesk(list, CurrentDesk); - } /****************************************************************************** @@ -140,121 +138,130 @@ int ItemCountD(List *list ) Based on main() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; + char *temp, *s; #ifdef HAVE_SIGACTION - struct sigaction sigact; + struct sigaction sigact; #endif - /* Save the program name for error messages and config parsing */ - temp = argv[0]; - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - /* Setup my name */ - Module = safemalloc(strlen(temp)+2); - strcpy(Module,"*"); - strcat(Module, temp); - Clength = strlen(Module); - - /* Open the console for messages */ - OpenConsole(); - - if((argc != 6)&&(argc != 7)) { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module, - VERSION); - ConsoleMessage("%s Version %s should only be executed by fvwm!\n",Module, - VERSION); - exit(1); - } - + /* Save the program name for error messages and config parsing */ + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + /* Setup my name */ + size_t name_len = strlen(temp); + Module = xmalloc(name_len + 2); + strlcpy(Module, "*", name_len + 2); + strlcat(Module, temp, name_len + 2); + Clength = strlen(Module); + + /* Open the console for messages */ + OpenConsole(); + + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", Module, + VERSION); + ConsoleMessage( + "%s Version %s should only be executed by fvwm!\n", Module, + VERSION); + exit(1); + } - if ((argc==7)&&(!strcasecmp(argv[6],"Transient"))) Transient=1; + if ((argc == 7) && (!strcasecmp(argv[6], "Transient"))) + Transient = 1; - Fvwm_fd[0] = atoi(argv[1]); - Fvwm_fd[1] = atoi(argv[2]); + Fvwm_fd[0] = atoi(argv[1]); + Fvwm_fd[1] = atoi(argv[2]); #ifdef HAVE_SIGACTION #ifdef SA_INTERRUPT - sigact.sa_flags = SA_INTERRUPT; + sigact.sa_flags = SA_INTERRUPT; #else - sigact.sa_flags = 0; + sigact.sa_flags = 0; #endif - sigemptyset(&sigact.sa_mask); - sigact.sa_handler = TerminateHandler; - sigaction(SIGPIPE, &sigact, NULL); - sigaction(SIGTERM, &sigact, NULL); + sigemptyset(&sigact.sa_mask); + sigact.sa_handler = TerminateHandler; + sigaction(SIGPIPE, &sigact, NULL); + sigaction(SIGTERM, &sigact, NULL); #else - signal(SIGPIPE, TerminateHandler); - signal(SIGTERM, TerminateHandler); + signal(SIGPIPE, TerminateHandler); + signal(SIGTERM, TerminateHandler); #ifdef HAVE_SIGINTERRUPT - siginterrupt(SIGPIPE, True); - siginterrupt(SIGTERM, True); + siginterrupt(SIGPIPE, True); + siginterrupt(SIGTERM, True); #endif #endif - /* Parse the config file */ - ParseConfig(); + /* Parse the config file */ + ParseConfig(); - /* Setup the XConnection */ - StartMeUp(); - XSetErrorHandler(ErrorHandler); + /* Setup the XConnection */ + StartMeUp(); + XSetErrorHandler(ErrorHandler); - InitPictureCMap(dpy, Root); + InitPictureCMap(dpy, Root); - InitArray(&buttons,0,0,win_width, fontheight+6); - InitList(&windows); + InitArray(&buttons, 0, 0, win_width, fontheight + 6); + InitList(&windows); - fd_width = GetFdWidth(); + fd_width = GetFdWidth(); - /* Request a list of all windows, - * wait for ConfigureWindow packets */ + /* Request a list of all windows, + * wait for ConfigureWindow packets */ - SetMessageMask(Fvwm_fd,M_CONFIGURE_WINDOW | M_RES_CLASS | M_RES_NAME | - M_ADD_WINDOW | M_DESTROY_WINDOW | M_ICON_NAME | - M_DEICONIFY | M_ICONIFY | M_END_WINDOWLIST | - M_NEW_DESK | M_NEW_PAGE | M_FOCUS_CHANGE | M_WINDOW_NAME | + SetMessageMask(Fvwm_fd, M_CONFIGURE_WINDOW | M_RES_CLASS | M_RES_NAME | + M_ADD_WINDOW | M_DESTROY_WINDOW | + M_ICON_NAME | M_DEICONIFY | M_ICONIFY | + M_END_WINDOWLIST | M_NEW_DESK | M_NEW_PAGE | + M_FOCUS_CHANGE | M_WINDOW_NAME | #ifdef MINI_ICONS - M_MINI_ICON | + M_MINI_ICON | #endif - M_STRING); + M_STRING); - SendFvwmPipe("Send_WindowList",0); + SendFvwmPipe("Send_WindowList", 0); - /* Recieve all messages from Fvwm */ - atexit(ShutMeDown); - MainEventLoop(); - return 0; + /* Recieve all messages from Fvwm */ + atexit(ShutMeDown); + MainEventLoop(); + return 0; } - /****************************************************************************** MainEventLoop - Read and redraw until we die, blocking when can't read ******************************************************************************/ -void MainEventLoop(void) +void +MainEventLoop(void) { -fd_set readset; - - while( !isTerminated ) { - FD_ZERO(&readset); - FD_SET(Fvwm_fd[1],&readset); - FD_SET(x_fd,&readset); - - /* This code restyled after FvwmIconMan, which is simpler. - * The biggest advantage over the original approach is - * having one fewer select statements - */ - XFlush(dpy); - if (select(fd_width,SELECT_TYPE_ARG234 &readset,NULL,NULL,NULL) > 0) { - - if (FD_ISSET(x_fd,&readset) || XPending(dpy)) LoopOnEvents(); - if (FD_ISSET(Fvwm_fd[1],&readset)) ReadFvwmPipe(); - - } - - } /* while */ + fd_set readset; + + sandbox_x11_only("FvwmWinList"); + sandbox_x11_only("FvwmWinList"); + + while (!isTerminated) { + FD_ZERO(&readset); + FD_SET(Fvwm_fd[1], &readset); + FD_SET(x_fd, &readset); + + /* This code restyled after FvwmIconMan, which is simpler. + * The biggest advantage over the original approach is + * having one fewer select statements + */ + XFlush(dpy); + if (select(fd_width, SELECT_TYPE_ARG234 & readset, NULL, NULL, + NULL) > 0) { + if (FD_ISSET(x_fd, &readset) || XPending(dpy)) + LoopOnEvents(); + if (FD_ISSET(Fvwm_fd[1], &readset)) + ReadFvwmPipe(); + } + + } /* while */ } /****************************************************************************** @@ -262,15 +269,15 @@ fd_set readset; Originally Loop() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ReadFvwmPipe(void) +void +ReadFvwmPipe(void) { - unsigned long header[HEADER_SIZE],*body; + unsigned long header[HEADER_SIZE], *body; - if(ReadFvwmPacket(Fvwm_fd[1],header,&body) > 0) - { - ProcessMessage(header[1],body); - free(body); - } + if (ReadFvwmPacket(Fvwm_fd[1], header, &body) > 0) { + ProcessMessage(header[1], body); + free(body); + } } /****************************************************************************** @@ -278,119 +285,129 @@ void ReadFvwmPipe(void) Skeleton based on processmessage() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ProcessMessage(unsigned long type,unsigned long *body) +void +ProcessMessage(unsigned long type, unsigned long *body) { - int redraw=0,i; - long flags; - char *name,*string; - static int current_focus=-1; - - FvwmPicture p; - - switch(type) - { - case M_ADD_WINDOW: - case M_CONFIGURE_WINDOW: - if ((i = FindItem(&windows,body[0]))!=-1) - { - if(UpdateItemDesk(&windows, i, body[7]) > 0) - { - AdjustWindow(); - RedrawWindow(1); - } - break; - } - - if (!(body[8]&WINDOWLISTSKIP) || !UseSkipList) - AddItem(&windows,body[0],body[8], body[7] /* desk */); - break; - case M_DESTROY_WINDOW: - if ((i=DeleteItem(&windows,body[0]))==-1) break; - RemoveButton(&buttons,i); - if (WindowIsUp) - AdjustWindow(); - - redraw=1; - break; + int redraw = 0, i; + long flags; + char *name, *string; + static int current_focus = -1; + + FvwmPicture p; + + switch (type) { + case M_ADD_WINDOW: + case M_CONFIGURE_WINDOW: + if ((i = FindItem(&windows, body[0])) != -1) { + if (UpdateItemDesk(&windows, body[0], body[7]) > 0) { + UpdateButtonDesk(&buttons, i, body[7]); + AdjustWindow(); + RedrawWindow(1); + } + break; + } + + if (!(body[8] & WINDOWLISTSKIP) || !UseSkipList) + AddItem(&windows, body[0], body[8], body[7] /* desk */); + break; + case M_DESTROY_WINDOW: + if ((i = DeleteItem(&windows, body[0])) == -1) + break; + RemoveButton(&buttons, i); + if (WindowIsUp) + AdjustWindow(); + + redraw = 1; + break; #ifdef MINI_ICONS - case M_MINI_ICON: - if ((i=FindItem(&windows,body[0]))==-1) break; - - if (UpdateButton(&buttons,i,NULL,-1)!=-1) - { - p.width = body[3]; - p.height = body[4]; - p.depth = body[5]; - p.picture = body[6]; - p.mask = body[7]; - - UpdateButtonPicture(&buttons, i, &p); - redraw = 0; - } - break; + case M_MINI_ICON: + if ((i = FindItem(&windows, body[0])) == -1) + break; + + if (UpdateButton(&buttons, i, NULL, -1) != -1) { + p.width = body[3]; + p.height = body[4]; + p.depth = body[5]; + p.picture = body[6]; + p.mask = body[7]; + + UpdateButtonPicture(&buttons, i, &p); + redraw = 0; + } + break; #endif - case M_WINDOW_NAME: - case M_ICON_NAME: - if ((type==M_ICON_NAME && !UseIconNames) || - (type==M_WINDOW_NAME && UseIconNames)) break; - if ((i=UpdateItemName(&windows,body[0],(char *)&body[3]))==-1) break; - string=(char *)&body[3]; - name=makename(string,ItemFlags(&windows,body[0])); - if (UpdateButton(&buttons,i,name,-1)==-1) - { - AddButton(&buttons, name, NULL, 1); - UpdateButtonSet(&buttons,i,ItemFlags(&windows,body[0])&ICONIFIED?1:0); - UpdateButtonDesk(&buttons,i,ItemDesk(&windows, body[0])); - } - free(name); - if (WindowIsUp) AdjustWindow(); - redraw=1; - break; - case M_DEICONIFY: - case M_ICONIFY: - if ((i=FindItem(&windows,body[0]))==-1) break; - flags=ItemFlags(&windows,body[0]); - if (type==M_DEICONIFY && !(flags&ICONIFIED)) break; - if (type==M_ICONIFY && flags&ICONIFIED) break; - flags^=ICONIFIED; - UpdateItemFlags(&windows,body[0],flags); - string=ItemName(&windows,i); - name=makename(string,flags); - if (UpdateButton(&buttons,i,name,-1)!=-1) redraw=1; - if (i!=current_focus||(flags&ICONIFIED)) - if (UpdateButtonSet(&buttons,i,(flags&ICONIFIED) ? 1 : 0)!=-1) redraw=1; - free(name); - break; - case M_FOCUS_CHANGE: - if ((i=FindItem(&windows,body[0]))!=-1) - { - flags=ItemFlags(&windows,body[0]); - UpdateItemFlags(&windows,body[0],flags); - RadioButton(&buttons,i); - } - else - RadioButton(&buttons,-1); - redraw = 1; - break; - case M_END_WINDOWLIST: - if (!WindowIsUp) MakeMeWindow(); - redraw = 1; - break; - case M_NEW_DESK: - CurrentDesk = body[0]; - if(ShowCurrentDesk) - { - AdjustWindow(); - RedrawWindow(1); - } - break; - case M_NEW_PAGE: - break; - } - - if (redraw && WindowIsUp==1) RedrawWindow(0); + case M_WINDOW_NAME: + case M_ICON_NAME: + if ((type == M_ICON_NAME && !UseIconNames) || + (type == M_WINDOW_NAME && UseIconNames)) + break; + if ((i = UpdateItemName(&windows, body[0], (char *)&body[3])) == + -1) + break; + string = (char *)&body[3]; + name = makename(string, ItemFlags(&windows, body[0])); + if (UpdateButton(&buttons, i, name, -1) == -1) { + AddButton(&buttons, name, NULL, 1); + UpdateButtonSet(&buttons, i, + ItemFlags(&windows, body[0]) & ICONIFIED ? 1 : 0); + UpdateButtonDesk( + &buttons, i, ItemDesk(&windows, body[0])); + } + free(name); + if (WindowIsUp) + AdjustWindow(); + redraw = 1; + break; + case M_DEICONIFY: + case M_ICONIFY: + if ((i = FindItem(&windows, body[0])) == -1) + break; + flags = ItemFlags(&windows, body[0]); + if (type == M_DEICONIFY && !(flags & ICONIFIED)) + break; + if (type == M_ICONIFY && flags & ICONIFIED) + break; + flags ^= ICONIFIED; + UpdateItemFlags(&windows, body[0], flags); + string = ItemName(&windows, i); + name = makename(string, flags); + if (UpdateButton(&buttons, i, name, -1) != -1) + redraw = 1; + if (i != current_focus || (flags & ICONIFIED)) + if (UpdateButtonSet( + &buttons, i, (flags & ICONIFIED) ? 1 : 0) != -1) + redraw = 1; + free(name); + break; + case M_FOCUS_CHANGE: + if ((i = FindItem(&windows, body[0])) != -1) { + flags = ItemFlags(&windows, body[0]); + UpdateItemFlags(&windows, body[0], flags); + RadioButton(&buttons, i); + } else + RadioButton(&buttons, -1); + redraw = 1; + break; + case M_END_WINDOWLIST: + if (!WindowIsUp) + MakeMeWindow(); + redraw = 1; + break; + case M_NEW_DESK: + CurrentDesk = body[0]; + if (ShowCurrentDesk) { + AdjustWindow(); + RedrawWindow(1); + } + break; + case M_NEW_PAGE: + break; + } + + if (redraw && WindowIsUp == 1) + RedrawWindow(0); } /****************************************************************************** @@ -398,37 +415,39 @@ void ProcessMessage(unsigned long type,unsigned long *body) Based on SendInfo() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void SendFvwmPipe(char *message,unsigned long window) +void +SendFvwmPipe(char *message, unsigned long window) { - int w; - char *hold,*temp,*temp_msg; - - hold=message; - - while(1) - { - temp=strchr(hold,','); - if (temp!=NULL) - { - temp_msg=safemalloc(temp-hold+1); - strncpy(temp_msg,hold,(temp-hold)); - temp_msg[(temp-hold)]='\0'; - hold=temp+1; - } else temp_msg=hold; - - write(Fvwm_fd[0],&window, sizeof(unsigned long)); - - w=strlen(temp_msg); - write(Fvwm_fd[0],&w,sizeof(int)); - write(Fvwm_fd[0],temp_msg,w); - - /* keep going */ - w=1; - write(Fvwm_fd[0],&w,sizeof(int)); - - if(temp_msg!=hold) free(temp_msg); - else break; - } + int w; + char *hold, *temp, *temp_msg; + + hold = message; + + while (1) { + temp = strchr(hold, ','); + if (temp != NULL) { + temp_msg = xmalloc(temp - hold + 1); + strncpy(temp_msg, hold, (temp - hold)); + temp_msg[(temp - hold)] = '\0'; + hold = temp + 1; + } else + temp_msg = hold; + + write(Fvwm_fd[0], &window, sizeof(unsigned long)); + + w = strlen(temp_msg); + write(Fvwm_fd[0], &w, sizeof(int)); + write(Fvwm_fd[0], temp_msg, w); + + /* keep going */ + w = 1; + write(Fvwm_fd[0], &w, sizeof(int)); + + if (temp_msg != hold) + free(temp_msg); + else + break; + } } /*********************************************************************** @@ -436,88 +455,92 @@ void SendFvwmPipe(char *message,unsigned long window) Based on DeadPipe() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. **********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - /* ShutMeDown(1); */ - /* - * do not call ShutMeDown, it may make X calls which are not allowed - * in a signal hander. - * - * THIS IS NO LONGER A SIGNAL HANDLER - we may now shut down gracefully - * NOTE: ShutMeDown will now be called automatically by exit(). - */ - exit(1); + /* ShutMeDown(1); */ + /* + * do not call ShutMeDown, it may make X calls which are not allowed + * in a signal hander. + * + * THIS IS NO LONGER A SIGNAL HANDLER - we may now shut down gracefully + * NOTE: ShutMeDown will now be called automatically by exit(). + */ + exit(1); } /****************************************************************************** WaitForExpose - Used to wait for expose event so we don't draw too early ******************************************************************************/ -void WaitForExpose(void) +void +WaitForExpose(void) { - XEvent Event; - - while(1) - { - /* - * Temporary solution to stop the process blocking - * in XNextEvent once we have been asked to quit. - * There is still a small race condition between - * checking the flag and calling the X-Server, but - * we can fix that ... - */ - if (isTerminated) - { - /* Just exit - the installed exit-procedure will clean up */ - exit(0); - } - /**/ - - XNextEvent(dpy,&Event); - if (Event.type==Expose) - { - if (Event.xexpose.count==0) break; - } - } + XEvent Event; + + while (1) { + if (isTerminated) { + exit(0); + } + + if (XCheckTypedEvent(dpy, Expose, &Event)) { + if (Event.xexpose.count == 0) + break; + } else if (isTerminated) { + exit(0); + } else { + XNextEvent(dpy, &Event); + if (Event.type == Expose) { + if (Event.xexpose.count == 0) + break; + } + } + } } /****************************************************************************** RedrawWindow - Update the needed lines and erase any old ones ******************************************************************************/ -void RedrawWindow(int force) +void +RedrawWindow(int force) { - DrawButtonArray(&buttons, force); - if (XQLength(dpy) && !force) LoopOnEvents(); + DrawButtonArray(&buttons, force); + if (XQLength(dpy) && !force) + LoopOnEvents(); } /****************************************************************************** ConsoleMessage - Print a message on the console. Works like printf. ******************************************************************************/ -void ConsoleMessage(const char *fmt, ...) +void +ConsoleMessage(const char *fmt, ...) { #ifndef NO_CONSOLE - va_list args; - FILE *filep; - - if (console==NULL) filep=stderr; - else filep=console; - va_start(args,fmt); - vfprintf(filep,fmt,args); - va_end(args); + va_list args; + FILE *filep; + + if (console == NULL) + filep = stderr; + else + filep = console; + va_start(args, fmt); + vfprintf(filep, fmt, args); + va_end(args); #endif } /****************************************************************************** OpenConsole - Open the console as a way of sending messages ******************************************************************************/ -int OpenConsole(void) +int +OpenConsole(void) { #ifndef NO_CONSOLE - if ((console=fopen("/dev/console","w"))==NULL) { - fprintf(stderr,"%s: cannot open console\n",Module); - return 0; - } + if ((console = fopen("/dev/console", "w")) == NULL) { + fprintf(stderr, "%s: cannot open console\n", Module); + return 0; + } #endif - return 1; + return 1; } /****************************************************************************** @@ -525,486 +548,536 @@ int OpenConsole(void) Based on part of main() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ParseConfig(void) +void +ParseConfig(void) { - char *tline; - - GetConfigLine(Fvwm_fd,&tline); - while(tline != (char *)0) - { - if(strlen(tline)>1) - { - if(strncasecmp(tline, CatString3(Module, "Font",""),Clength+4)==0) - CopyString(&font_string,&tline[Clength+4]); - else if(strncasecmp(tline,CatString3(Module,"Fore",""), Clength+4)==0) - CopyString(&ForeColor[0],&tline[Clength+4]); - else if(strncasecmp(tline,CatString3(Module,"IconFore",""), Clength+8)==0) - CopyString(&ForeColor[1],&tline[Clength+8]); - else if(strncasecmp(tline,CatString3(Module,"FocusFore",""), Clength+9)==0) - { - CopyString(&ForeColor[2],&tline[Clength+9]); - CopyString(&ForeColor[3],&tline[Clength+9]); - } - else if(strncasecmp(tline,CatString3(Module, "Geometry",""), Clength+8)==0) - CopyString(&geometry,&tline[Clength+8]); - else if(strncasecmp(tline,CatString3(Module, "Back",""), Clength+4)==0) - CopyString(&BackColor[0],&tline[Clength+4]); - else if(strncasecmp(tline,CatString3(Module,"IconBack",""), Clength+8)==0) - CopyString(&BackColor[1],&tline[Clength+8]); - else if(strncasecmp(tline,CatString3(Module,"FocusBack",""), Clength+9)==0) - { - CopyString(&BackColor[2],&tline[Clength+9]); - CopyString(&BackColor[3],&tline[Clength+9]); - } - else if(strncasecmp(tline,CatString3(Module, "NoAnchor",""), - Clength+8)==0) Anchor=0; - else if(strncasecmp(tline,CatString3(Module, "Action",""), Clength+6)==0) - LinkAction(&tline[Clength+6]); - else if(strncasecmp(tline,CatString3(Module, "UseSkipList",""), - Clength+11)==0) UseSkipList=1; - else if(strncasecmp(tline,CatString3(Module, "UseIconNames",""), - Clength+12)==0) UseIconNames=1; - else if(strncasecmp(tline,CatString3(Module, "ShowCurrentDesk",""), - Clength+15)==0) ShowCurrentDesk=1; - else if(strncasecmp(tline,CatString3(Module, "LeftJustify",""), - Clength+11)==0) LeftJustify=1; - else if(strncasecmp(tline,CatString3(Module, "TruncateLeft",""), - Clength+12)==0) TruncateLeft=1; - else if(strncasecmp(tline,CatString3(Module, "MinWidth",""), - Clength+8)==0) MinWidth=atoi(&tline[Clength+8]); - else if(strncasecmp(tline,CatString3(Module, "MaxWidth",""), - Clength+8)==0) MaxWidth=atoi(&tline[Clength+8]); - else if(strncasecmp(tline,CatString3(Module, "DontDepressFocus",""), - Clength+16)==0) ShowFocus=0; + char *tline; + + GetConfigLine(Fvwm_fd, &tline); + while (tline != (char *)0) { + if (strlen(tline) > 1) { + if (strncasecmp(tline, CatString3(Module, "Font", ""), + Clength + 4) == 0) + CopyString(&font_string, &tline[Clength + 4]); + else if (strncasecmp(tline, + CatString3(Module, "Fore", ""), + Clength + 4) == 0) + CopyString(&ForeColor[0], &tline[Clength + 4]); + else if (strncasecmp(tline, + CatString3(Module, "IconFore", ""), + Clength + 8) == 0) + CopyString(&ForeColor[1], &tline[Clength + 8]); + else if (strncasecmp(tline, + CatString3(Module, "FocusFore", ""), + Clength + 9) == 0) { + CopyString(&ForeColor[2], &tline[Clength + 9]); + CopyString(&ForeColor[3], &tline[Clength + 9]); + } else if (strncasecmp(tline, + CatString3(Module, "Geometry", ""), + Clength + 8) == 0) + CopyString(&geometry, &tline[Clength + 8]); + else if (strncasecmp(tline, + CatString3(Module, "Back", ""), + Clength + 4) == 0) + CopyString(&BackColor[0], &tline[Clength + 4]); + else if (strncasecmp(tline, + CatString3(Module, "IconBack", ""), + Clength + 8) == 0) + CopyString(&BackColor[1], &tline[Clength + 8]); + else if (strncasecmp(tline, + CatString3(Module, "FocusBack", ""), + Clength + 9) == 0) { + CopyString(&BackColor[2], &tline[Clength + 9]); + CopyString(&BackColor[3], &tline[Clength + 9]); + } else if (strncasecmp(tline, + CatString3(Module, "NoAnchor", ""), + Clength + 8) == 0) + Anchor = 0; + else if (strncasecmp(tline, + CatString3(Module, "Action", ""), + Clength + 6) == 0) + LinkAction(&tline[Clength + 6]); + else if (strncasecmp(tline, + CatString3(Module, "UseSkipList", ""), + Clength + 11) == 0) + UseSkipList = 1; + else if (strncasecmp(tline, + CatString3(Module, "UseIconNames", ""), + Clength + 12) == 0) + UseIconNames = 1; + else if (strncasecmp(tline, + CatString3(Module, "ShowCurrentDesk", ""), + Clength + 15) == 0) + ShowCurrentDesk = 1; + else if (strncasecmp(tline, + CatString3(Module, "LeftJustify", ""), + Clength + 11) == 0) + LeftJustify = 1; + else if (strncasecmp(tline, + CatString3(Module, "TruncateLeft", ""), + Clength + 12) == 0) + TruncateLeft = 1; + else if (strncasecmp(tline, + CatString3(Module, "MinWidth", ""), + Clength + 8) == 0) + MinWidth = atoi(&tline[Clength + 8]); + else if (strncasecmp(tline, + CatString3(Module, "MaxWidth", ""), + Clength + 8) == 0) + MaxWidth = atoi(&tline[Clength + 8]); + else if (strncasecmp(tline, + CatString3(Module, "DontDepressFocus", ""), + Clength + 16) == 0) + ShowFocus = 0; + } + GetConfigLine(Fvwm_fd, &tline); } - GetConfigLine(Fvwm_fd,&tline); - } } /****************************************************************************** LoopOnEvents - Process all the X events we get ******************************************************************************/ -void LoopOnEvents(void) +void +LoopOnEvents(void) { - int num; - char buffer[10]; - XEvent Event; - Window dummyroot,dummychild; - int x,x1,y,y1; - unsigned int dummy1; - - if (Transient && !Checked) - { - XQueryPointer(dpy,win,&dummyroot,&dummychild,&x1,&y1,&x,&y,&dummy1); - num=WhichButton(&buttons,x,y); - if (num!=-1) - { - Pressed=1; - ButPressed=num; - SwitchButton(&buttons,num); - } else Pressed=0; - Checked=1; - } - - while(XPending(dpy)) - { - XNextEvent(dpy,&Event); - - switch(Event.type) - { - case ButtonRelease: - if (Pressed) - { - num=WhichButton(&buttons,Event.xbutton.x,Event.xbutton.y); - if (num!=-1) - { - SendFvwmPipe(ClickAction[(Transient) ? 0:Event.xbutton.button-1], - ItemID(&windows,num)); - SwitchButton(&buttons,num); - } - } - if (Transient) exit(0); - Pressed=0; - ButPressed=-1; - break; - case ButtonPress: - num=WhichButton(&buttons,Event.xbutton.x,Event.xbutton.y); - if (num != -1) - { - SwitchButton(&buttons,num); - ButPressed=num; - } else ButPressed=-1; - Pressed=1; - break; - case Expose: - if (Event.xexpose.count==0) - RedrawWindow(1); - break; - case KeyPress: - num=XLookupString(&Event.xkey,buffer,10,NULL,0); - if (num==1) - { - if (buffer[0]=='q' || buffer[0]=='Q') exit(0); - else if (buffer[0]=='i' || buffer[0]=='I') PrintList(&windows); - else if (buffer[0]=='b' || buffer[0]=='B') PrintButtons(&buttons); - } - break; - case ClientMessage: - if ((Event.xclient.format==32) && (Event.xclient.data.l[0]==wm_del_win)) - exit(0); - case EnterNotify: - if (!SomeButtonDown(Event.xcrossing.state)) break; - num=WhichButton(&buttons,Event.xcrossing.x,Event.xcrossing.y); - if (num!=-1) - { - SwitchButton(&buttons,num); - ButPressed=num; - } else ButPressed=-1; - Pressed=1; - break; - case LeaveNotify: - if (!SomeButtonDown(Event.xcrossing.state)) break; - if (ButPressed!=-1) SwitchButton(&buttons,ButPressed); - Pressed=0; - break; - case MotionNotify: - if (!Pressed) break; - num=WhichButton(&buttons,Event.xmotion.x,Event.xmotion.y); - if (num==ButPressed) break; - if (ButPressed!=-1) SwitchButton(&buttons,ButPressed); - if (num!=-1) - { - SwitchButton(&buttons,num); - ButPressed=num; - } - else ButPressed=-1; - - break; - } - } -} + int num; + char buffer[10]; + XEvent Event; + Window dummyroot, dummychild; + int x, x1, y, y1; + unsigned int dummy1; + + if (Transient && !Checked) { + XQueryPointer(dpy, win, &dummyroot, &dummychild, &x1, &y1, &x, + &y, &dummy1); + num = WhichButton(&buttons, x, y); + if (num != -1) { + Pressed = 1; + ButPressed = num; + SwitchButton(&buttons, num); + } else + Pressed = 0; + Checked = 1; + } + while (XPending(dpy)) { + XNextEvent(dpy, &Event); + + switch (Event.type) { + case ButtonRelease: + if (Pressed) { + num = WhichButton( + &buttons, Event.xbutton.x, Event.xbutton.y); + if (num != -1) { + SendFvwmPipe( + ClickAction[(Transient) ? + 0 : + Event.xbutton + .button - + 1], + ItemID(&windows, num)); + SwitchButton(&buttons, num); + } + } + if (Transient) + exit(0); + Pressed = 0; + ButPressed = -1; + break; + case ButtonPress: + num = WhichButton( + &buttons, Event.xbutton.x, Event.xbutton.y); + if (num != -1) { + SwitchButton(&buttons, num); + ButPressed = num; + } else + ButPressed = -1; + Pressed = 1; + break; + case Expose: + if (Event.xexpose.count == 0) + RedrawWindow(1); + break; + case KeyPress: + num = XLookupString(&Event.xkey, buffer, 10, NULL, 0); + if (num == 1) { + if (buffer[0] == 'q' || buffer[0] == 'Q') + exit(0); + else if (buffer[0] == 'i' || buffer[0] == 'I') + PrintList(&windows); + else if (buffer[0] == 'b' || buffer[0] == 'B') + PrintButtons(&buttons); + } + break; + case ClientMessage: + if ((Event.xclient.format == 32) && + (Event.xclient.data.l[0] == wm_del_win)) + exit(0); + case EnterNotify: + if (!SomeButtonDown(Event.xcrossing.state)) + break; + num = WhichButton( + &buttons, Event.xcrossing.x, Event.xcrossing.y); + if (num != -1) { + SwitchButton(&buttons, num); + ButPressed = num; + } else + ButPressed = -1; + Pressed = 1; + break; + case LeaveNotify: + if (!SomeButtonDown(Event.xcrossing.state)) + break; + if (ButPressed != -1) + SwitchButton(&buttons, ButPressed); + Pressed = 0; + break; + case MotionNotify: + if (!Pressed) + break; + num = WhichButton( + &buttons, Event.xmotion.x, Event.xmotion.y); + if (num == ButPressed) + break; + if (ButPressed != -1) + SwitchButton(&buttons, ButPressed); + if (num != -1) { + SwitchButton(&buttons, num); + ButPressed = num; + } else + ButPressed = -1; + + break; + } + } +} /****************************************************************************** find_frame_window - looks for ancestor that is a child of the root Cribbed from FvwmIconMan/x.c - maybe should be in a library Returns the root-child and fills in off_x, off_y to give offset ******************************************************************************/ -Window find_frame_window (Window win, int *off_x, int *off_y) +Window +find_frame_window(Window win, int *off_x, int *off_y) { - Window root, parent, *junkw; - int junki; - XWindowAttributes attr; - - while (1) { - XQueryTree (dpy, win, &root, &parent, &junkw, &junki); - if (junkw) - XFree (junkw); - if (parent == root) - break; - XGetWindowAttributes (dpy, win, &attr); - *off_x += attr.x + attr.border_width; - *off_y += attr.y + attr.border_width; - win = parent; - } - - return win; + Window root, parent, *junkw; + int junki; + XWindowAttributes attr; + + while (1) { + junkw = NULL; + if (XQueryTree(dpy, win, &root, &parent, &junkw, &junki) && + junkw) + XFree(junkw); + if (parent == root) + break; + XGetWindowAttributes(dpy, win, &attr); + *off_x += attr.x + attr.border_width; + *off_y += attr.y + attr.border_width; + win = parent; + } + + return win; } /****************************************************************************** AdjustWindow - Resize the window according to maxwidth by number of buttons ******************************************************************************/ -void AdjustWindow(void) +void +AdjustWindow(void) { - int new_width=0,new_height=0,tw,i,total,off_x,off_y; - char *temp; - Window frame; - XWindowAttributes win_attr, frame_attr; - - total = ItemCountD(&windows ); - if (!total) - { - if (WindowIsUp==1) - { - XUnmapWindow(dpy,win); - WindowIsUp=2; - } - return; - } - for(i=0;i0) win_height = new_height; - if (new_width>0) win_width = new_width; - if (WindowIsUp==2) - { - XMapWindow(dpy,win); - WindowIsUp=1; - WaitForExpose(); - } + new_width = max(new_width, tw); + } + } + new_width = max(new_width, MinWidth); + new_width = min(new_width, MaxWidth); + new_height = (total * (fontheight + 6 + 1)); + if (WindowIsUp && + (new_height != win_height || new_width != win_width)) { + if (Anchor) { + off_x = off_y = 0; + MyXGrabServer(dpy); + frame = find_frame_window(win, &off_x, &off_y); + XGetWindowAttributes(dpy, frame, &frame_attr); + XGetWindowAttributes(dpy, win, &win_attr); + win_x = frame_attr.x + frame_attr.border_width + off_x; + win_y = frame_attr.y + frame_attr.border_width + off_y; + + if (win_grav == SouthEastGravity || + win_grav == NorthEastGravity) + win_x += win_attr.width - new_width; + if (win_grav == SouthEastGravity || + win_grav == SouthWestGravity) + win_y += win_attr.height - new_height; + + XMoveResizeWindow( + dpy, win, win_x, win_y, new_width, new_height); + MyXUngrabServer(dpy); + } else + XResizeWindow(dpy, win, new_width, new_height); + } + UpdateArray(&buttons, -1, -1, new_width, -1); + if (new_height > 0) + win_height = new_height; + if (new_width > 0) + win_width = new_width; + if (WindowIsUp == 2) { + XMapWindow(dpy, win); + WindowIsUp = 1; + WaitForExpose(); + } } /****************************************************************************** makename - Based on the flags return me '(name)' or 'name' ******************************************************************************/ -char *makename(const char *string,long flags) +char * +makename(const char *string, long flags) { -char *ptr; - ptr=safemalloc(strlen(string)+3); - *ptr = '\0'; - if (flags&ICONIFIED) strcpy(ptr,"("); - strcat(ptr,string); - if (flags&ICONIFIED) strcat(ptr,")"); - return ptr; + char *ptr; + size_t name_len = strlen(string); + size_t extra = (flags & ICONIFIED) ? 2 : 1; + ptr = xmalloc(name_len + extra); + ptr[0] = '\0'; + if (flags & ICONIFIED) + strlcpy(ptr, "(", name_len + extra); + strlcat(ptr, string, name_len + extra); + if (flags & ICONIFIED) + strlcat(ptr, ")", name_len + extra); + return ptr; } /****************************************************************************** LinkAction - Link an response to a users action ******************************************************************************/ -void LinkAction(char *string) +void +LinkAction(char *string) { -char *temp; - temp=string; - while(isspace(*temp)) temp++; - if(strncasecmp(temp, "Click1", 6)==0) - CopyString(&ClickAction[0],&temp[6]); - else if(strncasecmp(temp, "Click2", 6)==0) - CopyString(&ClickAction[1],&temp[6]); - else if(strncasecmp(temp, "Click3", 6)==0) - CopyString(&ClickAction[2],&temp[6]); - else if(strncasecmp(temp, "Enter", 5)==0) - CopyString(&EnterAction,&temp[5]); + char *temp; + temp = string; + while (isspace(*temp)) + temp++; + if (strncasecmp(temp, "Click1", 6) == 0) + CopyString(&ClickAction[0], &temp[6]); + else if (strncasecmp(temp, "Click2", 6) == 0) + CopyString(&ClickAction[1], &temp[6]); + else if (strncasecmp(temp, "Click3", 6) == 0) + CopyString(&ClickAction[2], &temp[6]); + else if (strncasecmp(temp, "Enter", 5) == 0) + CopyString(&EnterAction, &temp[5]); } /****************************************************************************** MakeMeWindow - Create and setup the window we will need ******************************************************************************/ -void MakeMeWindow(void) +void +MakeMeWindow(void) { - XSizeHints hints; - XGCValues gcval; - unsigned long gcmask; - unsigned int dummy1, dummy2; - int x, y, ret, count; - Window dummyroot, dummychild; - int i; - - - if ((count = ItemCountD(&windows))==0 && Transient) exit(0); - AdjustWindow(); - - hints.width=win_width; - hints.height=win_height; - hints.win_gravity=NorthWestGravity; - hints.flags=PSize|PWinGravity|PResizeInc; - hints.width_inc=0; - hints.height_inc=0; - - if (geometry!= NULL) - { - ret=XParseGeometry(geometry,&x,&y,&dummy1,&dummy2); - - if (ret&XValue && ret &YValue) - { - hints.x=x; - if (ret&XNegative) - hints.x+=XDisplayWidth(dpy,screen)-win_width; - - hints.y=y; - if (ret&YNegative) - hints.y+=XDisplayHeight(dpy,screen)-win_height; - - hints.flags|=USPosition; - } - - if (ret&XNegative) - { - if (ret&YNegative) hints.win_gravity=SouthEastGravity; - else hints.win_gravity=NorthEastGravity; - } - else - { - if (ret&YNegative) hints.win_gravity=SouthWestGravity; - else hints.win_gravity=NorthWestGravity; - } - - } - - if (Transient) - { - XQueryPointer(dpy,Root,&dummyroot,&dummychild,&hints.x,&hints.y,&x,&y,&dummy1); - hints.win_gravity=NorthWestGravity; - hints.flags |= USPosition; - } - win_grav=hints.win_gravity; - win_x=hints.x; - win_y=hints.y; - - - for (i = 0; i != MAX_COLOUR_SETS; i++) - if(d_depth < 2) - { - back[i] = GetColor("white"); - fore[i] = GetColor("black"); - } - else - { - back[i] = GetColor(BackColor[i] == NULL ? BackColor[0] : BackColor[i]); - fore[i] = GetColor(ForeColor[i] == NULL ? ForeColor[0] : ForeColor[i]); - } - - win=XCreateSimpleWindow(dpy,Root,hints.x,hints.y,hints.width,hints.height,0, - fore[0],back[0]); - - wm_del_win=XInternAtom(dpy,"WM_DELETE_WINDOW",False); - XSetWMProtocols(dpy,win,&wm_del_win,1); - - XSetWMNormalHints(dpy,win,&hints); - - if (!Transient) - { - XGrabButton(dpy,1,AnyModifier,win,True,GRAB_EVENTS,GrabModeAsync, - GrabModeAsync,None,None); - XGrabButton(dpy,2,AnyModifier,win,True,GRAB_EVENTS,GrabModeAsync, - GrabModeAsync,None,None); - XGrabButton(dpy,3,AnyModifier,win,True,GRAB_EVENTS,GrabModeAsync, - GrabModeAsync,None,None); - SetMwmHints(MWM_DECOR_ALL|MWM_DECOR_RESIZEH|MWM_DECOR_MAXIMIZE|MWM_DECOR_MINIMIZE, - MWM_FUNC_ALL|MWM_FUNC_RESIZE|MWM_FUNC_MAXIMIZE|MWM_FUNC_MINIMIZE, - MWM_INPUT_MODELESS); - } - else - { - SetMwmHints(0,MWM_FUNC_ALL,MWM_INPUT_MODELESS); - } - - for (i = 0; i != MAX_COLOUR_SETS; i++) - { - gcval.foreground=fore[i]; - gcval.background=back[i]; - gcval.font=ButtonFont->fid; - gcmask=GCForeground|GCBackground|GCFont; - graph[i]=XCreateGC(dpy,Root,gcmask,&gcval); - - if(d_depth < 2) - gcval.foreground=GetShadow(fore[i]); - else - gcval.foreground=GetShadow(back[i]); - gcval.background=back[i]; - gcmask=GCForeground|GCBackground; - shadow[i]=XCreateGC(dpy,Root,gcmask,&gcval); - - gcval.foreground=GetHilite(back[i]); - gcval.background=back[i]; - gcmask=GCForeground|GCBackground; - hilite[i]=XCreateGC(dpy,Root,gcmask,&gcval); - - gcval.foreground=back[i]; - gcmask=GCForeground; - background[i]=XCreateGC(dpy,Root,gcmask,&gcval); - } - - XSelectInput(dpy,win,(ExposureMask | KeyPressMask)); - - ChangeWindowName(&Module[1]); - - if (ItemCountD(&windows) > 0) - { - XMapRaised(dpy,win); - WaitForExpose(); - WindowIsUp=1; - } else WindowIsUp=2; - - if (Transient) - { - if ( XGrabPointer(dpy,win,True,GRAB_EVENTS,GrabModeAsync,GrabModeAsync, - None,None,CurrentTime)!=GrabSuccess) exit(1); - XQueryPointer(dpy,Root,&dummyroot,&dummychild,&hints.x,&hints.y,&x,&y,&dummy1); - if (!SomeButtonDown(dummy1)) exit(0); - } + XSizeHints hints; + XGCValues gcval; + unsigned long gcmask; + unsigned int dummy1, dummy2; + int x, y, ret, count; + Window dummyroot, dummychild; + int i; + + if ((count = ItemCountD(&windows)) == 0 && Transient) + exit(0); + AdjustWindow(); + + hints.width = win_width; + hints.height = win_height; + hints.win_gravity = NorthWestGravity; + hints.flags = PSize | PWinGravity | PResizeInc; + hints.width_inc = 0; + hints.height_inc = 0; + + if (geometry != NULL) { + ret = XParseGeometry(geometry, &x, &y, &dummy1, &dummy2); + + if (ret & XValue && ret & YValue) { + hints.x = x; + if (ret & XNegative) + hints.x += + XDisplayWidth(dpy, screen) - win_width; + + hints.y = y; + if (ret & YNegative) + hints.y += + XDisplayHeight(dpy, screen) - win_height; + + hints.flags |= USPosition; + } + + if (ret & XNegative) { + if (ret & YNegative) + hints.win_gravity = SouthEastGravity; + else + hints.win_gravity = NorthEastGravity; + } else { + if (ret & YNegative) + hints.win_gravity = SouthWestGravity; + else + hints.win_gravity = NorthWestGravity; + } + } + if (Transient) { + XQueryPointer(dpy, Root, &dummyroot, &dummychild, &hints.x, + &hints.y, &x, &y, &dummy1); + hints.win_gravity = NorthWestGravity; + hints.flags |= USPosition; + } + win_grav = hints.win_gravity; + win_x = hints.x; + win_y = hints.y; + + for (i = 0; i != MAX_COLOUR_SETS; i++) + if (d_depth < 2) { + back[i] = GetColor("white"); + fore[i] = GetColor("black"); + } else { + back[i] = GetColor( + BackColor[i] == NULL ? BackColor[0] : BackColor[i]); + fore[i] = GetColor( + ForeColor[i] == NULL ? ForeColor[0] : ForeColor[i]); + } + + win = XCreateSimpleWindow(dpy, Root, hints.x, hints.y, hints.width, + hints.height, 0, fore[0], back[0]); + + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + XSetWMProtocols(dpy, win, &wm_del_win, 1); + + XSetWMNormalHints(dpy, win, &hints); + + if (!Transient) { + XGrabButton(dpy, 1, AnyModifier, win, True, GRAB_EVENTS, + GrabModeAsync, GrabModeAsync, None, None); + XGrabButton(dpy, 2, AnyModifier, win, True, GRAB_EVENTS, + GrabModeAsync, GrabModeAsync, None, None); + XGrabButton(dpy, 3, AnyModifier, win, True, GRAB_EVENTS, + GrabModeAsync, GrabModeAsync, None, None); + SetMwmHints(MWM_DECOR_ALL | MWM_DECOR_RESIZEH | + MWM_DECOR_MAXIMIZE | MWM_DECOR_MINIMIZE, + MWM_FUNC_ALL | MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE | + MWM_FUNC_MINIMIZE, + MWM_INPUT_MODELESS); + } else { + SetMwmHints(0, MWM_FUNC_ALL, MWM_INPUT_MODELESS); + } + + for (i = 0; i != MAX_COLOUR_SETS; i++) { + gcval.foreground = fore[i]; + gcval.background = back[i]; + gcval.font = ButtonFont->fid; + gcmask = GCForeground | GCBackground | GCFont; + graph[i] = XCreateGC(dpy, Root, gcmask, &gcval); + + if (d_depth < 2) + gcval.foreground = GetShadow(fore[i]); + else + gcval.foreground = GetShadow(back[i]); + gcval.background = back[i]; + gcmask = GCForeground | GCBackground; + shadow[i] = XCreateGC(dpy, Root, gcmask, &gcval); + + gcval.foreground = GetHilite(back[i]); + gcval.background = back[i]; + gcmask = GCForeground | GCBackground; + hilite[i] = XCreateGC(dpy, Root, gcmask, &gcval); + + gcval.foreground = back[i]; + gcmask = GCForeground; + background[i] = XCreateGC(dpy, Root, gcmask, &gcval); + } + + XSelectInput(dpy, win, (ExposureMask | KeyPressMask)); + + ChangeWindowName(&Module[1]); + + if (ItemCountD(&windows) > 0) { + XMapRaised(dpy, win); + WaitForExpose(); + WindowIsUp = 1; + } else + WindowIsUp = 2; + + if (Transient) { + if (XGrabPointer(dpy, win, True, GRAB_EVENTS, GrabModeAsync, + GrabModeAsync, None, None, CurrentTime) != GrabSuccess) + exit(1); + XQueryPointer(dpy, Root, &dummyroot, &dummychild, &hints.x, + &hints.y, &x, &y, &dummy1); + if (!SomeButtonDown(dummy1)) + exit(0); + } } /****************************************************************************** StartMeUp - Do X initialization things ******************************************************************************/ -void StartMeUp(void) +void +StartMeUp(void) { - if (!(dpy = XOpenDisplay(""))) - { - fprintf(stderr,"%s: can't open display %s", Module, - XDisplayName("")); - exit (1); - } - x_fd = XConnectionNumber(dpy); - screen= DefaultScreen(dpy); - Root = RootWindow(dpy, screen); - d_depth = DefaultDepth(dpy, screen); - - ScreenHeight = DisplayHeight(dpy,screen); - ScreenWidth = DisplayWidth(dpy,screen); + if (!(dpy = XOpenDisplay(""))) { + fprintf(stderr, "%s: can't open display %s", Module, + XDisplayName("")); + exit(1); + } + x_fd = XConnectionNumber(dpy); + screen = DefaultScreen(dpy); + Root = RootWindow(dpy, screen); + d_depth = DefaultDepth(dpy, screen); - if ((ButtonFont=XLoadQueryFont(dpy,font_string))==NULL) - { - if ((ButtonFont=XLoadQueryFont(dpy,"fixed"))==NULL) exit(1); - } + ScreenHeight = DisplayHeight(dpy, screen); + ScreenWidth = DisplayWidth(dpy, screen); - fontheight = ButtonFont->ascent+ButtonFont->descent; + if ((ButtonFont = XLoadQueryFont(dpy, font_string)) == NULL) { + if ((ButtonFont = XLoadQueryFont(dpy, "fixed")) == NULL) + exit(1); + } - win_width=XTextWidth(ButtonFont,"XXXXXXXXXXXXXXX",10); + fontheight = ButtonFont->ascent + ButtonFont->descent; + win_width = XTextWidth(ButtonFont, "XXXXXXXXXXXXXXX", 10); } /****************************************************************************** ShutMeDown - Do X client cleanup ******************************************************************************/ -void ShutMeDown(void) +void +ShutMeDown(void) { - FreeList(&windows); - FreeAllButtons(&buttons); -/* XFreeGC(dpy,graph);*/ - if (WindowIsUp) XDestroyWindow(dpy,win); - XCloseDisplay(dpy); + FreeList(&windows); + FreeAllButtons(&buttons); + /* XFreeGC(dpy,graph);*/ + if (WindowIsUp) + XDestroyWindow(dpy, win); + XCloseDisplay(dpy); } /****************************************************************************** @@ -1012,16 +1085,17 @@ void ShutMeDown(void) Original work from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ChangeWindowName(char *str) +void +ChangeWindowName(char *str) { -XTextProperty name; - if (XStringListToTextProperty(&str,1,&name) == 0) { - fprintf(stderr,"%s: cannot allocate window name.\n",Module); - return; - } - XSetWMName(dpy,win,&name); - XSetWMIconName(dpy,win,&name); - XFree(name.value); + XTextProperty name; + if (XStringListToTextProperty(&str, 1, &name) == 0) { + fprintf(stderr, "%s: cannot allocate window name.\n", Module); + return; + } + XSetWMName(dpy, win, &name); + XSetWMIconName(dpy, win, &name); + XFree(name.value); } /************************************************************************** @@ -1035,42 +1109,39 @@ XTextProperty name; * Never check for MWM_RUNNING property.May be considered bad. */ -void SetMwmHints(unsigned int value, unsigned int funcs, unsigned int input) +void +SetMwmHints(unsigned int value, unsigned int funcs, unsigned int input) { -PropMwmHints prop; - - if (MwmAtom==None) - { - MwmAtom=XInternAtom(dpy,"_MOTIF_WM_HINTS",False); - } - if (MwmAtom!=None) - { - /* sh->mwm.decorations contains OR of the MWM_DECOR_XXXXX */ - prop.decorations= value; - prop.functions = funcs; - prop.inputMode = input; - prop.flags = MWM_HINTS_DECORATIONS| MWM_HINTS_FUNCTIONS | MWM_HINTS_INPUT_MODE; - - /* HOP - LA! */ - XChangeProperty (dpy,win, - MwmAtom, MwmAtom, - 32, PropModeReplace, - (unsigned char *)&prop, - PROP_MWM_HINTS_ELEMENTS); - } + PropMwmHints prop; + + if (MwmAtom == None) { + MwmAtom = XInternAtom(dpy, "_MOTIF_WM_HINTS", False); + } + if (MwmAtom != None) { + /* sh->mwm.decorations contains OR of the MWM_DECOR_XXXXX */ + prop.decorations = value; + prop.functions = funcs; + prop.inputMode = input; + prop.flags = MWM_HINTS_DECORATIONS | MWM_HINTS_FUNCTIONS | + MWM_HINTS_INPUT_MODE; + + /* HOP - LA! */ + XChangeProperty(dpy, win, MwmAtom, MwmAtom, 32, PropModeReplace, + (unsigned char *)&prop, PROP_MWM_HINTS_ELEMENTS); + } } /************************************************************************ X Error Handler ************************************************************************/ -int ErrorHandler(Display *d, XErrorEvent *event) +int +ErrorHandler(Display *d, XErrorEvent *event) { - char errmsg[256]; - - XGetErrorText(d, event->error_code, errmsg, sizeof(errmsg)); - ConsoleMessage("%s failed request: %s\n", Module, errmsg); - ConsoleMessage("Major opcode: 0x%x, resource id: 0x%x\n", - event->request_code, (unsigned int)event->resourceid); - return 0; -} + char errmsg[256]; + XGetErrorText(d, event->error_code, errmsg, sizeof(errmsg)); + ConsoleMessage("%s failed request: %s\n", Module, errmsg); + ConsoleMessage("Major opcode: 0x%x, resource id: 0x%x\n", + event->request_code, (unsigned int)event->resourceid); + return 0; +} Index: fvwm/modules/FvwmWinList/FvwmWinList.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/FvwmWinList.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/FvwmWinList.h --- fvwm/modules/FvwmWinList/FvwmWinList.h +++ fvwm/modules/FvwmWinList/FvwmWinList.h @@ -1,6 +1,11 @@ -#include "fvwmlib.h" +#ifndef FVWM_WINLIST_H +#define FVWM_WINLIST_H -/* FvwmWinList Module for Fvwm. +#include + +#include "fvwmlib.h" + +/* FvwmWinList Module for Fvwm. * * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or * Mike_Finger@atk.com) @@ -20,55 +25,54 @@ * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ -#define STICKY (1<<2) /* Does window stick to glass? */ -#define ONTOP (1<<1) /* does window stay on top */ -#define BORDER (1<<13) /* Is this decorated with border*/ -#define TITLE (1<<14) /* Is this decorated with title */ -#define ICONIFIED (1<<16) /* is it an icon now? */ -#define TRANSIENT (1<<17) /* is it a transient window? */ -#define WINDOWLISTSKIP (1<<3) +#define STICKY (1 << 2) /* Does window stick to glass? */ +#define ONTOP (1 << 1) /* does window stay on top */ +#define BORDER (1 << 13) /* Is this decorated with border*/ +#define TITLE (1 << 14) /* Is this decorated with title */ +#define ICONIFIED (1 << 16) /* is it an icon now? */ +#define TRANSIENT (1 << 17) /* is it a transient window? */ +#define WINDOWLISTSKIP (1 << 3) /* Motif window hints */ -typedef struct -{ - CARD32 flags; - CARD32 functions; - CARD32 decorations; - INT32 inputMode; +typedef struct { + CARD32 flags; + CARD32 functions; + CARD32 decorations; + INT32 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_INPUT_MODE (1L << 2) +#define MWM_HINTS_FUNCTIONS (1L << 0) +#define MWM_HINTS_DECORATIONS (1L << 1) +#define MWM_HINTS_INPUT_MODE (1L << 2) /* 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) /* values for MwmHints.input_mode */ -#define MWM_INPUT_MODELESS 0 -#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 -#define MWM_INPUT_SYSTEM_MODAL 2 -#define MWM_INPUT_FULL_APPLICATION_MODAL 3 +#define MWM_INPUT_MODELESS 0 +#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 +#define MWM_INPUT_SYSTEM_MODAL 2 +#define MWM_INPUT_FULL_APPLICATION_MODAL 3 /* 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 /* default values for configuration parameters */ #define DEFMAXWIDTH 10000 @@ -79,26 +83,28 @@ typedef PropMotifWmHints PropMwmHints; **************************************************************************/ void MainEventLoop(void); void ReadFvwmPipe(void); -void ProcessMessage(unsigned long type,unsigned long *body); -void SendFvwmPipe(char *message,unsigned long window); +void ProcessMessage(unsigned long type, unsigned long *body); +void SendFvwmPipe(char *message, unsigned long window); void DeadPipe(int nonsense) __attribute__((noreturn)); void MakeMeWindow(void); void WaitForExpose(void); void RedrawWindow(int force); void StartMeUp(void); void ShutMeDown(void); -void ConsoleMessage(const char *fmt,...) __attribute__((format(printf,1,2))); +void ConsoleMessage(const char *fmt, ...) __attribute__((format(printf, 1, 2))); int OpenConsole(void); void ParseConfig(void); void LoopOnEvents(void); void AdjustWindow(void); -char *makename(const char *string,long flags); +char *makename(const char *string, long flags); void ChangeWindowName(char *str); void LinkAction(char *string); void AddToSkipList(char *string); int InSkipList(char *string); void PrintSkipList(void); void FvwmNameMessage(long *body); -void SetMwmHints(unsigned int value,unsigned int funcs,unsigned int input); +void SetMwmHints(unsigned int value, unsigned int funcs, unsigned int input); int ErrorHandler(Display *d, XErrorEvent *event); + +#endif /* FVWM_WINLIST_H */ Index: fvwm/modules/FvwmWinList/List.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/List.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/List.c --- fvwm/modules/FvwmWinList/List.c +++ fvwm/modules/FvwmWinList/List.c @@ -1,325 +1,388 @@ -/* FvwmWinList Module for Fvwm. +/* FvwmWinList Module for Fvwm. * * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or * Mike_Finger@atk.com) * * The functions in this source file are the original work of Mike Finger. - * + * * No guarantees or warantees or anything are provided or implied in any way * whatsoever. Use this program at your own risk. Permission to use this * program for any purpose is given, as long as the copyright is kept intact. * - * Things to do: Convert to C++ (In Progress) */ -#include "config.h" -#include -#include #include "List.h" -#include "Mallocs.h" -#include "../../fvwm/module.h" #include +#include +#include + +#include "../../fvwm/module.h" #include "FvwmWinList.h" +#include "config.h" + +static void +UpdateString(char **string, char *value) +{ + size_t value_len; + + if (value == NULL) + return; + value_len = strlen(value); + if (*string == NULL) + *string = xmalloc(value_len + 1); + else + *string = xrealloc(*string, value_len + 1); + strlcpy(*string, value, value_len + 1); +} /****************************************************************************** InitList - Initialize the list ******************************************************************************/ -void InitList(List *list) +void +InitList(List *list) { - list->head=list->tail=NULL; - list->count=0; + list->head = list->tail = NULL; + list->count = 0; } /****************************************************************************** AddItem - Allocates spaces for and appends an item to the list ******************************************************************************/ -void AddItem(List *list, long id,long flags, long desk) +void +AddItem(List *list, long id, long flags, long desk) { -Item *new; - new=(Item *)safemalloc(sizeof(Item)); - new->id=id; - new->name=NULL; - new->flags=flags; - new->desk=desk; - new->next=NULL; - - if (list->tail==NULL) list->head=list->tail=new; - else { - list->tail->next=new; - list->tail=new; - } - list->count++; + Item *new; + new = (Item *)xmalloc(sizeof(Item)); + new->id = id; + new->name = NULL; + new->flags = flags; + new->desk = desk; + new->next = NULL; + + if (list->tail == NULL) + list->head = list->tail = new; + else { + list->tail->next = new; + list->tail = new; + } + list->count++; } /****************************************************************************** FindItem - Find the item in the list matching the id ******************************************************************************/ -int FindItem(List *list, long id) +int +FindItem(List *list, long id) { - Item *temp; - int i; - - for(i=0,temp=list->head;temp!=NULL && temp->id!=id;i++,temp=temp->next); - if (temp==NULL) return -1; - return i; + Item *temp; + int i; + + for (i = 0, temp = list->head; temp != NULL && temp->id != id; + i++, temp = temp->next) + ; + if (temp == NULL) + return -1; + return i; } - + /****************************************************************************** FindItemDesk - Find the item in the list matching the id, and desk id ******************************************************************************/ -int FindItemDesk(List *list, long id, long desk) +int +FindItemDesk(List *list, long id, long desk) { - Item *temp; - int i; - - for(i=0,temp=list->head;temp!=NULL && (temp->id!=id || temp->desk != desk) ;i++,temp=temp->next); - if (temp==NULL) return -1; - return i; + Item *temp; + int i; + + for (i = 0, temp = list->head; + temp != NULL && (temp->id != id || temp->desk != desk); + i++, temp = temp->next) + ; + if (temp == NULL) + return -1; + return i; } - /****************************************************************************** UpdateItem - Update the item in the list, setting name & flags as necessary. ******************************************************************************/ -int UpdateItemName(List *list, long id, char *string) +int +UpdateItemName(List *list, long id, char *string) { - Item *temp; - int i; - - for(i=0,temp=list->head;temp!=NULL && id!=temp->id;i++,temp=temp->next); - if (temp==NULL) return -1; - UpdateString(&temp->name, string); - return i; + Item *temp; + int i; + + for (i = 0, temp = list->head; temp != NULL && id != temp->id; + i++, temp = temp->next) + ; + if (temp == NULL) + return -1; + UpdateString(&temp->name, string); + return i; } /****************************************************************************** UpdateItemDesk - Update the item in the list, setting desk as necessary. - returns 1 if desk was updated, - returns 0, if not changed + returns 1 if desk was updated, + returns 0, if not changed returns -1 if not found ******************************************************************************/ -int UpdateItemDesk(List *list, long id, long desk) +int +UpdateItemDesk(List *list, long id, long desk) { - Item *temp; - int i; - - for(i=0,temp=list->head;temp != NULL && temp->id != id ;i++,temp=temp->next); -/* printf("sk=%ld %ld \n", id, temp->id); -*/ - if (temp ==NULL ) return -1; - -/* printf("dsk=%d\n", temp->desk); -*/ - if(temp->desk != desk) - { -/* printf("got a nonmatch\n"); -*/ - temp->desk = desk; - return 1; - } - - return 0; + Item *temp; + int i; + + for (i = 0, temp = list->head; temp != NULL && temp->id != id; + i++, temp = temp->next) + ; + /* printf("sk=%ld %ld \n", id, temp->id); + */ + if (temp == NULL) + return -1; + + /* printf("dsk=%d\n", temp->desk); + */ + if (temp->desk != desk) { + /* printf("got a nonmatch\n"); + */ + temp->desk = desk; + return 1; + } + + return 0; } -int UpdateItemFlags(List *list, long id, long flags) +int +UpdateItemFlags(List *list, long id, long flags) { -Item *temp; -int i; - for(i=0,temp=list->head;temp!=NULL && id!=temp->id;i++,temp=temp->next); - if (temp==NULL) return -1; - if (flags!=-1) temp->flags=flags; - return i; + Item *temp; + int i; + for (i = 0, temp = list->head; temp != NULL && id != temp->id; + i++, temp = temp->next) + ; + if (temp == NULL) + return -1; + if (flags != -1) + temp->flags = flags; + return i; } - + /****************************************************************************** FreeItem - Frees allocated space for an Item ******************************************************************************/ -void FreeItem(Item *ptr) +void +FreeItem(Item *ptr) { - if (ptr != NULL) { - if (ptr->name!=NULL) free(ptr->name); - free(ptr); - } + if (ptr != NULL) { + if (ptr->name != NULL) + free(ptr->name); + free(ptr); + } } /****************************************************************************** DeleteItem - Deletes an item from the list ******************************************************************************/ -int DeleteItem(List *list,long id) +int +DeleteItem(List *list, long id) { - Item *temp,*temp2; - int i; - - if (list->head==NULL) return -1; - if (list->head->id==id) - { - temp2=list->head; - temp=list->head=list->head->next; - i=-1; - } - else - { - for(i=0,temp=list->head;temp->next!=NULL && temp->next->id!=id; - i++,temp=temp->next); - if (temp->next==NULL) return -1; - temp2=temp->next; - temp->next=temp2->next; - } - - if (temp2==list->tail) list->tail=temp; - - FreeItem(temp2); - list->count--; - return i+1; + Item *temp, *temp2; + int i; + + if (list->head == NULL) + return -1; + if (list->head->id == id) { + temp2 = list->head; + temp = list->head = list->head->next; + i = -1; + } else { + for (i = 0, temp = list->head; + temp->next != NULL && temp->next->id != id; + i++, temp = temp->next) + ; + if (temp->next == NULL) + return -1; + temp2 = temp->next; + temp->next = temp2->next; + } + + if (temp2 == list->tail) + list->tail = temp; + + FreeItem(temp2); + list->count--; + return i + 1; } /****************************************************************************** FreeList - Free the entire list of Items ******************************************************************************/ -void FreeList(List *list) +void +FreeList(List *list) { - Item *temp,*temp2; - - for(temp=list->head;temp!=NULL;) - { - temp2=temp; - temp=temp->next; - FreeItem(temp2); - } - list->count=0; + Item *temp, *temp2; + + for (temp = list->head; temp != NULL;) { + temp2 = temp; + temp = temp->next; + FreeItem(temp2); + } + list->count = 0; } /****************************************************************************** PrintList - Print the list of item on the console. (Debugging) ******************************************************************************/ -void PrintList(List *list) +void +PrintList(List *list) { -Item *temp; - ConsoleMessage("List of Items:\n"); - ConsoleMessage(" %10s %-15s %-15s %-15s %-15s Flgs\n","ID","Name","I-Name", - "R-Name","R-Class"); - ConsoleMessage(" ---------- --------------- --------------- --------------- --------------- ----\n"); - for(temp=list->head;temp!=NULL;temp=temp->next) { - ConsoleMessage(" %10ld %-15.15s %4ld\n",temp->id, - (temp->name==NULL) ? "" : temp->name, - temp->flags); - } + Item *temp; + ConsoleMessage("List of Items:\n"); + ConsoleMessage(" %10s %-15s %-15s %-15s %-15s Flgs\n", "ID", "Name", + "I-Name", "R-Name", "R-Class"); + ConsoleMessage(" ---------- --------------- --------------- " + "--------------- --------------- ----\n"); + for (temp = list->head; temp != NULL; temp = temp->next) { + ConsoleMessage(" %10ld %-15.15s %4ld\n", temp->id, + (temp->name == NULL) ? "" : temp->name, temp->flags); + } } /****************************************************************************** ItemName - Return the name of an Item ******************************************************************************/ -char *ItemName(List *list, int n) +char * +ItemName(List *list, int n) { - Item *temp; - int i; - - for(i=0,temp=list->head;temp!=NULL && inext); - if (temp==NULL) return NULL; - return temp->name; + Item *temp; + int i; + + for (i = 0, temp = list->head; temp != NULL && i < n; + i++, temp = temp->next) + ; + if (temp == NULL) + return NULL; + return temp->name; } /****************************************************************************** ItemFlags - Return the flags for an item ******************************************************************************/ -long ItemFlags(List *list, long id) +long +ItemFlags(List *list, long id) { - Item *temp; + Item *temp; - for(temp=list->head; temp != NULL && id!=temp->id; temp=temp->next); - if (temp==NULL) - return -1; + for (temp = list->head; temp != NULL && id != temp->id; + temp = temp->next) + ; + if (temp == NULL) + return -1; - else return temp->flags; + else + return temp->flags; } /****************************************************************************** ItemDesk - Return the desk for an item ******************************************************************************/ -long ItemDesk(List *list, long id) +long +ItemDesk(List *list, long id) { - Item *temp; + Item *temp; - for(temp=list->head;temp!=NULL && id!=temp->id;temp=temp->next); + for (temp = list->head; temp != NULL && id != temp->id; + temp = temp->next) + ; - if (temp==NULL) return -1; - else return temp->desk; + if (temp == NULL) + return -1; + else + return temp->desk; } - /****************************************************************************** XorFlags - Exclusive of the flags with the specified value. ******************************************************************************/ -long XorFlags(List *list, int n, long value) +long +XorFlags(List *list, int n, long value) { - Item *temp; - int i; - long ret; - - for(i=0,temp=list->head;temp!=NULL && inext) - if (temp==NULL) return -1; - ret=temp->flags; - temp->flags^=value; - return ret; + Item *temp; + int i; + long ret; + + for (i = 0, temp = list->head; temp != NULL && i < n; + i++, temp = temp->next) + if (temp == NULL) + return -1; + ret = temp->flags; + temp->flags ^= value; + return ret; } /****************************************************************************** ItemCount - Return the number of items inthe list ******************************************************************************/ -int ItemCount(List *list) +int +ItemCount(List *list) { - return list->count; + return list->count; } /****************************************************************************** ItemCountDesk - Return the number of items inthe list, with desk desk ******************************************************************************/ -int ItemCountDesk(List *list, long desk) +int +ItemCountDesk(List *list, long desk) { - Item *temp; - int count=0; + Item *temp; + int count = 0; -/*return list->count;*/ + /*return list->count;*/ - for(temp=list->head; - temp != NULL; - temp = temp->next - ) - { - if(temp->desk == desk) - count++; - } + for (temp = list->head; temp != NULL; temp = temp->next) { + if (temp->desk == desk) + count++; + } - return count; + return count; } /****************************************************************************** ItemID - Return the ID of the item in the list. ******************************************************************************/ -long ItemID(List *list, int n) +long +ItemID(List *list, int n) { - Item *temp; - int i; - - for(i=0,temp=list->head;temp!=NULL && inext); - if (temp==NULL) return -1; - return temp->id; + Item *temp; + int i; + + for (i = 0, temp = list->head; temp != NULL && i < n; + i++, temp = temp->next) + ; + if (temp == NULL) + return -1; + return temp->id; } /****************************************************************************** CopyItem - Copy an item from one list to another ******************************************************************************/ -void CopyItem(List *dest, List *source, int n) +void +CopyItem(List *dest, List *source, int n) { - Item *temp; - int i; - - for(i=0,temp=source->head;temp!=NULL && inext); - if (temp==NULL) return; - AddItem(dest,temp->id,temp->flags, temp->desk); - UpdateItemName(dest,temp->id,temp->name); - DeleteItem(source,temp->id); + Item *temp; + int i; + + for (i = 0, temp = source->head; temp != NULL && i < n; + i++, temp = temp->next) + ; + if (temp == NULL) + return; + AddItem(dest, temp->id, temp->flags, temp->desk); + UpdateItemName(dest, temp->id, temp->name); + DeleteItem(source, temp->id); } - Index: fvwm/modules/FvwmWinList/List.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/List.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/List.h --- fvwm/modules/FvwmWinList/List.h +++ fvwm/modules/FvwmWinList/List.h @@ -1,36 +1,33 @@ -/* FvwmWinList Module for Fvwm. +/* FvwmWinList Module for Fvwm. * * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or * Mike_Finger@atk.com) * * The functions in this source file that are the original work of Mike Finger. - * + * * No guarantees or warantees or anything are provided or implied in any way * whatsoever. Use this program at your own risk. Permission to use this * program for any purpose is given, as long as the copyright is kept intact. * - * Things to do: Convert to C++ (In Progress) */ /* Structure definitions */ -typedef struct item -{ - long id; - char *name; - long flags; - long desk; - struct item *next; +typedef struct item { + long id; + char *name; + long flags; + long desk; + struct item *next; } Item; -typedef struct -{ - Item *head,*tail; - int count; +typedef struct { + Item *head, *tail; + int count; } List; /* Function Prototypes */ void InitList(List *list); -void AddItem(List *list, long id, long flags, long desk ); +void AddItem(List *list, long id, long flags, long desk); int FindItem(List *list, long id); int FindItemDesk(List *list, long id, long desk); @@ -38,15 +35,15 @@ int UpdateItemName(List *list, long id, char *string); int UpdateItemDesk(List *list, long id, long desk); int UpdateItemFlags(List *list, long id, long flags); void FreeItem(Item *ptr); -int DeleteItem(List *list,long id); +int DeleteItem(List *list, long id); void FreeList(List *list); void PrintList(List *list); char *ItemName(List *list, int n); -long ItemFlags(List *list, long id ); -long ItemFlags(List *list, long id ); +long ItemFlags(List *list, long id); +long ItemFlags(List *list, long id); long ItemDesk(List *list, long id); long XorFlags(List *list, int n, long value); int ItemCount(List *list); int ItemCountDesk(List *list, long desk); long ItemID(List *list, int n); -void CopyItem(List *dest,List *source,int n); +void CopyItem(List *dest, List *source, int n); Index: fvwm/modules/FvwmWinList/Makefile =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/Makefile,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/Makefile --- fvwm/modules/FvwmWinList/Makefile +++ fvwm/modules/FvwmWinList/Makefile @@ -5,7 +5,7 @@ .PATH: ${DIST}/modules/FvwmWinList PROG= FvwmWinList -SRCS= ButtonArray.c Colors.c FvwmWinList.c List.c Mallocs.c +SRCS= ButtonArray.c Colors.c FvwmWinList.c List.c LDADD+= -lXpm ${XLIB} BINDIR= ${FVWMLIBDIR} Index: fvwm/modules/FvwmWinList/Mallocs.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/Mallocs.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/Mallocs.c --- fvwm/modules/FvwmWinList/Mallocs.c +++ /dev/null @@ -1,58 +0,0 @@ -/* FvwmWinList Module for Fvwm. - * - * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or - * Mike_Finger@atk.com) - * - * The author makes not guarantees or warantees, either express or - * implied. Feel free to use any contained here for any purpose, as long - * and this and any other applicible copyrights are kept intact. - - * The functions in this source file that are based on part of the FvwmIdent - * module for Fvwm are noted by a small copyright atop that function, all others - * are copyrighted by Mike Finger. For those functions modified/used, here is - * the full, original copyright: - * - * Copyright 1994, Robert Nation and Nobutaka Suzuki. - * No guarantees or warantees or anything - * are provided or implied in any way whatsoever. Use this program at your - * own risk. Permission to use this program for any purpose is given, - * as long as the copyright is kept intact. */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include "../../libs/fvwmlib.h" - -extern char *Module; - -/****************************************************************************** - saferealloc - safely reallocate memory or exit if fails. (Doesn't work right) - (No kidding! Try it now ...) -******************************************************************************/ -char *saferealloc(char *ptr, size_t length) -{ -char *newptr; - - if(length <=0) length=1; - - /* If ptr is NULL then realloc does a malloc */ - newptr=realloc(ptr,length); - if (newptr == (char *)0) { - fprintf(stderr,"%s:realloc failed",Module); - exit(1); - } - return newptr; -} - -void UpdateString(char **string,const char *value) -{ - if (value==NULL) return; - *string = saferealloc(*string,strlen(value)+1); - strcpy(*string,value); -} - - Index: fvwm/modules/FvwmWinList/Mallocs.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/Mallocs.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/Mallocs.h --- fvwm/modules/FvwmWinList/Mallocs.h +++ /dev/null @@ -1,25 +0,0 @@ -/* FvwmWinList Module for Fvwm. - * - * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or - * Mike_Finger@atk.com) - * - * The author makes not guarantees or warantees, either express or - * implied. Feel free to use any contained here for any purpose, as long - * and this and any other applicible copyrights are kept intact. - - * The functions in this source file that are based on part of the FvwmIdent - * module for Fvwm are noted by a small copyright atop that function, all others - * are copyrighted by Mike Finger. For those functions modified/used, here is - * the full, original copyright: - * - * Copyright 1994, Robert Nation and Nobutaka Suzuki. - * No guarantees or warantees or anything - * are provided or implied in any way whatsoever. Use this program at your - * own risk. Permission to use this program for any purpose is given, - * as long as the copyright is kept intact. */ - -/* Function Prototypes */ -char *safemalloc(int length); -char *saferealloc(char *ptr, size_t length); -void UpdateString(char **string,const char *value); - Index: fvwm/modules/FvwmWinList/README =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/README,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/README --- fvwm/modules/FvwmWinList/README +++ fvwm/modules/FvwmWinList/README @@ -72,11 +72,8 @@ To do: (in no particular order) (ie. You make it wider you get 2 columns of buttons, etc.) - Fix the following: - - The function saferealloc, based on safemalloc by Rob Nation still doesn't - work correctly, I left it in the Mallocs.c file but I use the normal - realloc now. (Being lazy on this one) - - Make compile compatability for all systems - - Tune FvwmWinList to be more efficient (Low priority, right now) + - Make compile compatability for all systems + - Tune FvwmWinList to be more efficient (Low priority, right now) I am open to, actually I am trolling for, suggestions/improvments/ideas/rags on this. Index: fvwm/modules/Makefile.inc =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/Makefile.inc,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/Makefile.inc --- fvwm/modules/Makefile.inc +++ fvwm/modules/Makefile.inc @@ -7,7 +7,7 @@ FVWM_MAKEFILE_INC = done X11BASE?= /usr/X11R6 -CFLAGS+= -I${X11BASE}/include -I${.CURDIR}/../.. -I${.CURDIR}/../../libs +CFLAGS+= -std=c99 -I${X11BASE}/include -I${.CURDIR}/../.. -I${.CURDIR}/../../libs LDADD+= -L${X11BASE}/lib XLIB= -lX11 -lxcb -lXau -lXdmcp Index: fvwm/Makefile.inc =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/Makefile.inc,v retrieving revision 1.1 diff -u -r1.1 fvwm/Makefile.inc --- fvwm/Makefile.inc +++ fvwm/Makefile.inc @@ -5,7 +5,7 @@ FVWM_MAKEFILE_INC = done .include -CFLAGS+= -I${X11BASE}/include -I${.CURDIR} -I${.CURDIR}/.. \ +CFLAGS+= -std=c99 -I${X11BASE}/include -I${.CURDIR} -I${.CURDIR}/.. \ -I${.CURDIR}/../libs LDADD+= -L${X11BASE}/lib 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/docs/BUGS =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/docs/BUGS,v retrieving revision 1.1 diff -u -r1.1 fvwm/docs/BUGS --- fvwm/docs/BUGS +++ fvwm/docs/BUGS @@ -9,71 +9,17 @@ from our home page. ====================================================================== ====================================================================== - - No geometry can be specified for FvwmButtons panels. - Running fvwm2 on an XNest X server does not work well. - - FvwmSave and FvwmSaveDesk are not up to date. - The fvwm_convert script is not up to date. - - xscreensaver may not be able to allocate a private colormap - - FvwmButtons and possibly other modules may survive shutdown of the X - server. + - xscreensaver may not be able to allocate a private colormap. - AutoHide in FvwmTaskBar does not work well. See 'EdgeThickness' command in the manpage. - - DestroyMenu/DestroyFunc causes a coredump if a function/menu destroys - itself. - - Maximize does not work well when applied to a window that is not on - the current page. - - A piperead command may hang if used in .fvwm2rc (if the pipe is never - closed). - - StartsOnPage does not work as expected? Please read the manpage carefully. - ====================================================================== ====================================================================== -Configure remembers too many things, particularly with respect to the -optional libraries. If you ever need to re-run configure, using -different --with options, please remove "config.cache" file first. - ----------------------------------------------------------------------- - Binding a key to a window decoration but not to the window itself is discouraged because when the key-press event finally gets to the window it will be marked as SYNTHETIC and will be ignored by many applications. ----------------------------------------------------------------------- - -Sending DESTROY window manager options to applications is a bad way to -close them and should only be used as a last resort. Strange things -can happen. Please try DELETE and CLOSE first. - ----------------------------------------------------------------------- - -Some users have seen intermittent problems with XEmacs version 19.13 -not being refreshed correctly after a restart of fvwm2. If this -occurs, you should be able to open a new frame and delete the old one. -I can't debug this, as I don't see this problem. I don't know if the -problem is from XEmacs, fvwm2, or something specific to a few user's -setups. - ----------------------------------------------------------------------- - -Some users have been getting odd startup problems, like total lockups. -I cannot reproduce this, and have no idea why. Let me know if you see -this and find a way to consistently reproduce it. - -Actually, I've recently discovered that this is often from not having -a .fvwm2rc file, so check that first... But this is fixed in the -later versions. - ----------------------------------------------------------------------- - -Fvwm attempts to be ICCCM 1.1 compliant. In addition, ICCCM -states that it should be possible for applications to receive ANY -keystroke, which is not consistent with the keyboard shortcut approach -used in fvwm and most other window managers. In particular you -cannot have the same keyboard shortcuts working with your fvwm2 and -another fvwm2 running within Xnest (a nested X server). The same problem -exists with mouse bindings. - ----------------------------------------------------------------------- Index: fvwm/docs/TODO =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/docs/TODO,v retrieving revision 1.1 diff -u -r1.1 fvwm/docs/TODO --- fvwm/docs/TODO +++ fvwm/docs/TODO @@ -45,7 +45,6 @@ Bugfixes: - Change flags implementation to allow adding more Styles easily (bitfields?) - THE GREAT STYLE FLAG REWRITE (GSFR) - Rewrite VISIBLE/RAISED lags to do something comprehensible. - - Fix Restart to not pass original (fvwm specific) options to other wm's - Run profiling on FVWM to see if I can speed it up any more - Try to decrease memory usage a little more - clean up code duplication (esp in modules) - more stuff in @@ -57,19 +56,14 @@ Bugfixes: MotionThreshold not exceeded & ClickTime not exceeded -> DoubleClick - Make transient FvwmWinList reposition itself & pointer if popped up off the screen (like built in menus) - - Maximize XTerm, change font, UnMaximize, XTerm goes to wrong window size - (still unfixed on 28-Nov-1998) - Colormaps and xlock -install -mode blank (& swirl) interaction still isn't 100% correct? - bring back 'TogglePage'? - - Setting keys via FvwmTalk or Read requires Recapture to take effect? - System Modal dialogs bug - popup menus shouldn't be allowed?? I think this is ok, actually... - Fix FvwmDeskTopScale size calculation - Need to fix to work correctly under 24bit (TrueColor) displays - - Esc during moves, etc can result in windows being "lost" off desktop - Should also have way to make windows off desktop be recovered easier - - Transients of transients don't get raised correctly sometimes? ---------------------------------------------------------------------- Index: fvwm/docs/run_man2html.sh =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/docs/run_man2html.sh,v retrieving revision 1.1 diff -u -r1.1 fvwm/docs/run_man2html.sh --- fvwm/docs/run_man2html.sh +++ fvwm/docs/run_man2html.sh @@ -1,4 +1,4 @@ -#/bin/sh +#!/bin/sh # Modification History @@ -12,8 +12,8 @@ # If you run, run_man2html.sh fvwm2, this creates "fvwm2.html" in # the current directory. -name=`basename $1` -outfile=$name.html +name=$(basename "$1") +outfile="$name.html" # make header: echo " @@ -27,23 +27,23 @@ echo "

The Official FVWM Homepage - $name Man Page

-" > $outfile
+" >"$outfile"
 
 # Embed the text with some adjustment:
 # Italics are shown in yellow.  References, (if there were any)
 # would be shown in cyan.  Unfortunately bold stuff in man pages
 # is lost.  Maybe in the man command, maybe in man2html.
 # Output looks pretty good anyway (to my eyes).
-man $name | man2html -bare \
-  -uelem 'font color="yellow"'\
-  -belem 'font color="cyan"'\
-   >> $outfile
+man "$name" | man2html -bare \
+	-uelem 'font color="yellow"' \
+	-belem 'font color="cyan"' \
+	>>"$outfile"
 
 # make footer:
 echo "

+ on $(date) --> -" >> $outfile +" >>"$outfile" Index: fvwm/docs/txt2html.sh =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/docs/txt2html.sh,v retrieving revision 1.1 diff -u -r1.1 fvwm/docs/txt2html.sh --- fvwm/docs/txt2html.sh +++ fvwm/docs/txt2html.sh @@ -13,8 +13,8 @@ # This has to be run from the directory where the output file is wanted. # This is designed for the files, ChangeLog, TO-DO, FAQ -name=`basename $1` -outfile=$name.html +name=$(basename "$1") +outfile="$name.html" # make header: echo " @@ -28,18 +28,18 @@ echo "

The Official FVWM Homepage - $name Information

-" > $outfile
+" >"$outfile"
 
 # Embed the text with some adjustment:
 sed -e 's/&/\&/' \
-    -e 's//\>/' $1 >> $outfile
+	-e 's//\>/' "$1" >>"$outfile"
 
 # make footer:
 echo "

+ on $(date) --> -" >> $outfile +" >>"$outfile" Index: fvwm/utils/xpmroot.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/utils/xpmroot.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/utils/xpmroot.1 --- fvwm/utils/xpmroot.1 +++ fvwm/utils/xpmroot.1 @@ -1,7 +1,7 @@ .\" $OpenBSD: xpmroot.1,v 1.1.1.1 2006/11/26 10:53:57 matthieu Exp $ .\" t .\" @(#)xpmroot.1 1.01 8/10/93 -.TH XPMROOT 1 "13 August 1993" 1.01 +.TH XPMROOT 1 "August 13, 1993" "1.01" "FVWM Utilities" .UC .SH NAME xpmroot \- Sets the root window of the current X display to an Xpm pixmap @@ -10,8 +10,5 @@ xpmroot \- Sets the root window of the current X display to an Xpm pixmap .SH DESCRIPTION \fIxpmroot\fP reads the Xpm file specified in the command line and displays it in the root window. -.SH BUGS -Repeated use of xpmroot with different xpm pixmaps will use up slots in -your color table pretty darn fast. .SH AUTHOR Rob Nation Index: fvwm/utils/xpmroot.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/utils/xpmroot.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/utils/xpmroot.c --- fvwm/utils/xpmroot.c +++ fvwm/utils/xpmroot.c @@ -1,99 +1,152 @@ /**************************************************************************** * This is an all new program to set the root window to an Xpm pixmap. - * Copyright 1993, Rob Nation + * Copyright 1993, Rob Nation * You may use this file for anything you want, as long as the copyright * is kept intact. No guarantees of any sort are made in any way regarding * this program or anything related to it. ****************************************************************************/ -#include "config.h" - -#include -#include -#include -#include #include -#include "../libs/fvwmlib.h" +#include +#include #include /* Has to be after Intrinsic.h gets included */ +#include +#include +#include +#include + +#include "../libs/fvwmlib.h" +#include "config.h" +#include "../fvwm/fvwm_sandbox.h" -int save_colors = 0; Display *dpy; int screen; Window root; char *display_name = NULL; -void SetRootWindow(char *tline); +static void SetRootWindow( + char *tline, XWindowAttributes *root_attr, Atom colors_atom); +static void FreePreviousResources( + Atom pixmap_atom, Atom colors_atom, XWindowAttributes *root_attr); Pixmap rootXpm; -int main(int argc, char **argv) +int +main(int argc, char **argv) { - Atom prop, type; - int format; - unsigned long length, after; - unsigned char *data; - - if(argc != 2) - { - fprintf(stderr,"Xpmroot Version %s\n",VERSION); - fprintf(stderr,"Usage: xpmroot xpmfile\n"); - fprintf(stderr,"Try Again\n"); - exit(1); - } - dpy = XOpenDisplay(display_name); - if (!dpy) - { - fprintf(stderr, "Xpmroot: unable to open display '%s'\n", - XDisplayName (display_name)); - exit (2); - } - screen = DefaultScreen(dpy); - root = RootWindow(dpy, screen); - - SetRootWindow(argv[1]); - - prop = XInternAtom(dpy, "_XSETROOT_ID", False); - - (void)XGetWindowProperty(dpy, root, prop, 0L, 1L, True, AnyPropertyType, - &type, &format, &length, &after, &data); - if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0)) - XKillClient(dpy, *((Pixmap *)data)); - - XChangeProperty(dpy, root, prop, XA_PIXMAP, 32, PropModeReplace, - (unsigned char *) &rootXpm, 1); - XSetCloseDownMode(dpy, RetainPermanent); - XCloseDisplay(dpy); - return 0; + Atom prop, color_prop; + XWindowAttributes root_attr; + + if (argc != 2) { + fprintf(stderr, "Xpmroot Version %s\n", VERSION); + fprintf(stderr, "Usage: xpmroot xpmfile\n"); + fprintf(stderr, "Try Again\n"); + exit(1); + } + sandbox_xpmroot("xpmroot"); + dpy = XOpenDisplay(display_name); + if (!dpy) { + fprintf(stderr, "Xpmroot: unable to open display '%s'\n", + XDisplayName(display_name)); + exit(2); + } + screen = DefaultScreen(dpy); + root = RootWindow(dpy, screen); + XGetWindowAttributes(dpy, root, &root_attr); + + prop = XInternAtom(dpy, "_XSETROOT_ID", False); + color_prop = XInternAtom(dpy, "_XSETROOT_COLORS", False); + + FreePreviousResources(prop, color_prop, &root_attr); + + SetRootWindow(argv[1], &root_attr, color_prop); + + XChangeProperty(dpy, root, prop, XA_PIXMAP, 32, PropModeReplace, + (unsigned char *)&rootXpm, 1); + XSetCloseDownMode(dpy, RetainPermanent); + XCloseDisplay(dpy); + return 0; } +static void +SetRootWindow(char *tline, XWindowAttributes *root_attr, Atom colors_atom) +{ + XpmAttributes xpm_attributes; + Pixmap shapeMask; + int val; + + memset(&xpm_attributes, 0, sizeof(xpm_attributes)); + xpm_attributes.colormap = root_attr->colormap; + xpm_attributes.valuemask = XpmSize | XpmReturnAllocPixels | XpmColormap; + if ((val = XpmReadFileToPixmap(dpy, root, tline, &rootXpm, &shapeMask, + &xpm_attributes)) != XpmSuccess) { + if (val == XpmOpenFailed) + fprintf(stderr, "Couldn't open pixmap file\n"); + else if (val == XpmColorFailed) + fprintf(stderr, "Couldn't allocate required colors\n"); + else if (val == XpmFileInvalid) + fprintf(stderr, "Invalid Format for an Xpm File\n"); + else if (val == XpmColorError) + fprintf( + stderr, "Invalid Color specified in Xpm FIle\n"); + else if (val == XpmNoMemory) + fprintf(stderr, "Insufficient Memory\n"); + exit(1); + } -void SetRootWindow(char *tline) + if (shapeMask != None) + XFreePixmap(dpy, shapeMask); + + XSetWindowBackgroundPixmap(dpy, root, rootXpm); + XClearWindow(dpy, root); + + if ((xpm_attributes.valuemask & XpmReturnAllocPixels) && + xpm_attributes.nalloc_pixels > 0 && + xpm_attributes.alloc_pixels != NULL) { + XChangeProperty(dpy, root, colors_atom, XA_CARDINAL, 32, + PropModeReplace, + (unsigned char *)xpm_attributes.alloc_pixels, + (int)xpm_attributes.nalloc_pixels); + } else { + XDeleteProperty(dpy, root, colors_atom); + } + + XpmFreeAttributes(&xpm_attributes); +} + +static void +FreePreviousResources( + Atom pixmap_atom, Atom colors_atom, XWindowAttributes *root_attr) { - XWindowAttributes root_attr; - XpmAttributes xpm_attributes; - Pixmap shapeMask; - int val; - - XGetWindowAttributes(dpy,root,&root_attr); - xpm_attributes.colormap = root_attr.colormap; - xpm_attributes.valuemask = XpmSize | XpmReturnPixels|XpmColormap; - if((val = XpmReadFileToPixmap(dpy,root, tline, - &rootXpm, &shapeMask, - &xpm_attributes))!= XpmSuccess) - { - if(val == XpmOpenFailed) - fprintf(stderr, "Couldn't open pixmap file\n"); - else if(val == XpmColorFailed) - fprintf(stderr, "Couldn't allocate required colors\n"); - else if(val == XpmFileInvalid) - fprintf(stderr, "Invalid Format for an Xpm File\n"); - else if(val == XpmColorError) - fprintf(stderr, "Invalid Color specified in Xpm FIle\n"); - else if(val == XpmNoMemory) - fprintf(stderr, "Insufficient Memory\n"); - exit(1); - } - - XSetWindowBackgroundPixmap(dpy, root, rootXpm); - save_colors = 1; - XClearWindow(dpy,root); + Atom type; + int format; + unsigned long length, after; + unsigned char *data = NULL; + int visual_class = + (root_attr->visual != NULL) ? root_attr->visual->class : StaticGray; + Bool can_free_colors = + (visual_class == PseudoColor || visual_class == GrayScale || + visual_class == DirectColor); + + if (XGetWindowProperty(dpy, root, colors_atom, 0L, (~0L), True, + XA_CARDINAL, &type, &format, &length, &after, + &data) == Success) { + if (can_free_colors && type == XA_CARDINAL && format == 32 && + length > 0 && data != NULL) { + Pixel *pixels = (Pixel *)data; + XFreeColors( + dpy, root_attr->colormap, pixels, (int)length, 0); + } + if (data != NULL) + XFree(data); + } + data = NULL; + if (XGetWindowProperty(dpy, root, pixmap_atom, 0L, 1L, True, + AnyPropertyType, &type, &format, &length, &after, + &data) == Success) { + if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && + data != NULL) + XKillClient(dpy, *((Pixmap *)data)); + if (data != NULL) + XFree(data); + } } Index: fvwm/modules/FvwmAuto/FvwmAuto.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmAuto/FvwmAuto.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmAuto/FvwmAuto.c --- fvwm/modules/FvwmAuto/FvwmAuto.c +++ fvwm/modules/FvwmAuto/FvwmAuto.c @@ -24,7 +24,6 @@ #include "config.h" #include "../fvwm/fvwm_sandbox.h" -#endif #include #include @@ -124,7 +123,7 @@ main(int argc, char **argv) delay->tv_sec = sec; delay->tv_usec = usec; } - select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, + select(fd_width, & in_fdset, 0, 0, (focus_win == last_win) ? NULL : delay); #ifdef DEBUG fprintf(stderr, Index: fvwm/modules/FvwmBacker/FvwmBacker.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/FvwmBacker.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/FvwmBacker.c --- fvwm/modules/FvwmBacker/FvwmBacker.c +++ fvwm/modules/FvwmBacker/FvwmBacker.c @@ -43,8 +43,6 @@ #include #include -#endif /* Saul */ - #include #include @@ -164,11 +162,11 @@ EndLessLoop() tv.tv_sec = 0; tv.tv_usec = 0; - if (!select(fd_width, SELECT_TYPE_ARG234 & readset, NULL, NULL, + if (!select(fd_width, & readset, NULL, NULL, &tv)) { FD_ZERO(&readset); FD_SET(Fvwm_fd[1], &readset); - select(fd_width, SELECT_TYPE_ARG234 & readset, NULL, + select(fd_width, & readset, NULL, NULL, NULL); } Index: fvwm/modules/FvwmBanner/FvwmBanner.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBanner/FvwmBanner.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBanner/FvwmBanner.c --- fvwm/modules/FvwmBanner/FvwmBanner.c +++ fvwm/modules/FvwmBanner/FvwmBanner.c @@ -7,7 +7,6 @@ #include "config.h" #include "../../fvwm/fvwm_sandbox.h" -#endif #include #include @@ -190,7 +189,7 @@ main(int argc, char **argv) FD_SET(x_fd, &in_fdset); if (!XPending(dpy)) - retval = select(fd_width, SELECT_TYPE_ARG234 & in_fdset, + retval = select(fd_width, & in_fdset, 0, 0, &value); if (retval == 0) { Index: fvwm/modules/FvwmButtons/FvwmButtons.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/FvwmButtons.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/FvwmButtons.c --- fvwm/modules/FvwmButtons/FvwmButtons.c +++ fvwm/modules/FvwmButtons/FvwmButtons.c @@ -16,7 +16,6 @@ #include "config.h" #include "../../fvwm/fvwm_sandbox.h" -#endif #include #include @@ -857,7 +856,7 @@ Loop(void) PanelIndex = MainPanel; while (PanelIndex && PanelIndex->uber != - btn->uber) + btn->parent) PanelIndex = PanelIndex->next; UberButton = CurrentPanel ? @@ -1668,7 +1667,7 @@ My_XNextEvent(Display *Dpy, XEvent *event) FD_SET(x_fd, &in_fdset); FD_SET(fd[1], &in_fdset); - if (select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL) > 0) { + if (select(fd_width, & in_fdset, 0, 0, NULL) > 0) { if (FD_ISSET(x_fd, &in_fdset)) { if (XPending(Dpy)) { XNextEvent(Dpy, event); Index: fvwm/modules/FvwmButtons/draw.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/draw.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/draw.c --- fvwm/modules/FvwmButtons/draw.c +++ fvwm/modules/FvwmButtons/draw.c @@ -16,8 +16,6 @@ #include "config.h" -#endif - #include #include #include Index: fvwm/modules/FvwmIconBox/FvwmIconBox.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconBox/FvwmIconBox.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconBox/FvwmIconBox.c --- fvwm/modules/FvwmIconBox/FvwmIconBox.c +++ fvwm/modules/FvwmIconBox/FvwmIconBox.c @@ -20,7 +20,6 @@ #include "config.h" #include "../../fvwm/fvwm_sandbox.h" -#endif #include #include @@ -1928,7 +1927,7 @@ My_XNextEvent(Display *dpy, XEvent *event) FD_SET(x_fd, &in_fdset); FD_SET(fd[1], &in_fdset); - select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL); + select(fd_width, & in_fdset, 0, 0, NULL); if (FD_ISSET(x_fd, &in_fdset)) { if (XPending(dpy)) { Index: fvwm/modules/FvwmIconMan/FvwmIconMan.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/FvwmIconMan.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/FvwmIconMan.c --- fvwm/modules/FvwmIconMan/FvwmIconMan.c +++ fvwm/modules/FvwmIconMan/FvwmIconMan.c @@ -12,6 +12,7 @@ #include #include "../../fvwm/module.h" +#include "../../fvwm/fvwm_sandbox.h" #include "readconfig.h" #include "x.h" #include "xmanager.h" Index: fvwm/modules/FvwmIconMan/FvwmIconMan.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/FvwmIconMan.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/FvwmIconMan.h --- fvwm/modules/FvwmIconMan/FvwmIconMan.h +++ fvwm/modules/FvwmIconMan/FvwmIconMan.h @@ -47,7 +47,6 @@ #include #endif -extern void PrintMemuse(void); typedef unsigned long Ulong; typedef unsigned char Uchar; Index: fvwm/modules/FvwmIconMan/fvwm.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/fvwm.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/fvwm.c --- fvwm/modules/FvwmIconMan/fvwm.c +++ fvwm/modules/FvwmIconMan/fvwm.c @@ -577,8 +577,6 @@ ReadFvwmPipe(void) FvwmPacketHeader header; FvwmPacketBody *body; - PrintMemuse(); - ConsoleDebug(FVWM, "DEBUG: entering ReadFvwmPipe\n"); body_length = ReadFvwmPacket( Fvwm_fd[1], (unsigned long *)&header, (unsigned long **)&body); Index: fvwm/modules/FvwmIconMan/globals.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/globals.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/globals.c --- fvwm/modules/FvwmIconMan/globals.c +++ fvwm/modules/FvwmIconMan/globals.c @@ -31,7 +31,6 @@ init_win_manager(int id) globals.managers[id].index = id; #ifdef MINI_ICONS globals.managers[id].draw_icons = 0; -#endif globals.managers[id].res = SHOW_PAGE; globals.managers[id].window_up = 0; globals.managers[id].can_draw = 0; @@ -71,6 +70,7 @@ init_win_manager(int id) globals.managers[id].we_are_drawing = 1; globals.managers[id].configures_expected = 0; } +#endif void print_managers(void) Index: fvwm/modules/FvwmPager/FvwmPager.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmPager/FvwmPager.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmPager/FvwmPager.c --- fvwm/modules/FvwmPager/FvwmPager.c +++ fvwm/modules/FvwmPager/FvwmPager.c @@ -24,8 +24,6 @@ #include "config.h" #include "../../fvwm/fvwm_sandbox.h" -#endif /* Saul */ - #include #if HAVE_SYS_SELECT_H #include @@ -879,7 +877,7 @@ My_XNextEvent(Display *dpy, XEvent *event) FD_SET(x_fd, &in_fdset); FD_SET(fd[1], &in_fdset); - if (select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL) > 0) { + if (select(fd_width, & in_fdset, 0, 0, NULL) > 0) { if (FD_ISSET(x_fd, &in_fdset)) { if (XPending(dpy)) { XNextEvent(dpy, event); Index: fvwm/modules/FvwmRearrange/FvwmRearrange.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmRearrange/FvwmRearrange.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmRearrange/FvwmRearrange.c --- fvwm/modules/FvwmRearrange/FvwmRearrange.c +++ fvwm/modules/FvwmRearrange/FvwmRearrange.c @@ -29,7 +29,6 @@ #include "config.h" #include "../../fvwm/fvwm_sandbox.h" -#endif #if HAVE_SYS_SELECT_H #include Index: fvwm/modules/FvwmSave/FvwmSave.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSave/FvwmSave.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSave/FvwmSave.c --- fvwm/modules/FvwmSave/FvwmSave.c +++ fvwm/modules/FvwmSave/FvwmSave.c @@ -286,7 +286,7 @@ do_save(void) out = fopen(tname, "w+"); if (out == NULL) { fprintf(stderr, "%s: couldn't open %s for writing\n", - Myname, tname); + MyName, tname); return; } for (t = list_root; t != NULL; t = t->next) { Index: fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c --- fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c +++ fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c @@ -429,7 +429,7 @@ do_save(void) out = fopen(fnbuf, "w"); if (out == NULL) { fprintf(stderr, "%s: couldn't open %s for writing\n", - Myname, fnbuf); + MyName, fnbuf); return; } Index: fvwm/modules/FvwmScroll/GrabWindow.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmScroll/GrabWindow.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmScroll/GrabWindow.c --- fvwm/modules/FvwmScroll/GrabWindow.c +++ fvwm/modules/FvwmScroll/GrabWindow.c @@ -13,8 +13,6 @@ #include "config.h" -#endif - #include #include Index: fvwm/modules/FvwmTalk/FvwmTalk.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmTalk/FvwmTalk.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmTalk/FvwmTalk.c --- fvwm/modules/FvwmTalk/FvwmTalk.c +++ fvwm/modules/FvwmTalk/FvwmTalk.c @@ -17,7 +17,6 @@ #include "config.h" #include "../../fvwm/fvwm_sandbox.h" -#endif #include #include @@ -346,7 +345,7 @@ My_XNextEvent(Display *dpy, XEvent *event) FD_SET(x_fd, &in_fdset); FD_SET(fd[1], &in_fdset); - select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL); + select(fd_width, & in_fdset, 0, 0, NULL); if (FD_ISSET(x_fd, &in_fdset)) { if (XPending(dpy)) { Index: fvwm/modules/FvwmWinList/FvwmWinList.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/FvwmWinList.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/FvwmWinList.c --- fvwm/modules/FvwmWinList/FvwmWinList.c +++ fvwm/modules/FvwmWinList/FvwmWinList.c @@ -28,7 +28,6 @@ #ifndef NO_CONSOLE #define NO_CONSOLE -#endif #define YES "Yes" #define NO "No" @@ -48,12 +47,11 @@ #if HAVE_SYS_SELECT_H #include #endif +#endif #include #include -#endif - #include #include #include @@ -253,7 +251,7 @@ MainEventLoop(void) * having one fewer select statements */ XFlush(dpy); - if (select(fd_width, SELECT_TYPE_ARG234 & readset, NULL, NULL, + if (select(fd_width, & readset, NULL, NULL, NULL) > 0) { if (FD_ISSET(x_fd, &readset) || XPending(dpy)) LoopOnEvents();