diff options
author | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2006-11-26 10:53:58 +0000 |
---|---|---|
committer | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2006-11-26 10:53:58 +0000 |
commit | 1cb4778bcef21ea9015cfccdb99abb7a0e035d74 (patch) | |
tree | f164009397f9d3d5634c6f8a94b1542f793d9692 /app/fvwm/modules/FvwmWinList | |
parent | 841f8331c93ff96bd798e9a74ba10fab155da5c5 (diff) |
Importing from XF4, plus BSD make infrastructure
Diffstat (limited to 'app/fvwm/modules/FvwmWinList')
-rw-r--r-- | app/fvwm/modules/FvwmWinList/ButtonArray.c | 500 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/ButtonArray.h | 51 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/CHANGELOG | 96 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/Colors.c | 49 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/Colors.h | 19 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/FvwmWinList.1 | 162 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/FvwmWinList.c | 1076 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/FvwmWinList.h | 104 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/Imakefile | 12 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/List.c | 325 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/List.h | 51 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/Makefile | 14 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/Mallocs.c | 58 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/Mallocs.h | 25 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/README | 114 | ||||
-rw-r--r-- | app/fvwm/modules/FvwmWinList/config.sample | 17 |
16 files changed, 2673 insertions, 0 deletions
diff --git a/app/fvwm/modules/FvwmWinList/ButtonArray.c b/app/fvwm/modules/FvwmWinList/ButtonArray.c new file mode 100644 index 000000000..9be63e39c --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/ButtonArray.c @@ -0,0 +1,500 @@ +/* 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) + */ + +#include "config.h" + +#include <stdlib.h> +#include <stdio.h> +#include <X11/Xlib.h> + +#include "../../libs/fvwmlib.h" + +#include "ButtonArray.h" +#include "Mallocs.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 int LeftJustify, TruncateLeft, ShowFocus; + +extern long CurrentDesk; +extern int ShowCurrentDesk; + + +/************************************************************************* + * * + * Button handling functions and procedures * + * * + *************************************************************************/ + +/* ------------------------------------------------------------------------- + ButtonNew - Allocates and fills a new button structure + ------------------------------------------------------------------------- */ +Button *ButtonNew(char *title, Picture *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; +} + +/****************************************************************************** + InitArray - Initialize the arrary of buttons +******************************************************************************/ +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; +} + +/****************************************************************************** + UpdateArray - Update the array specifics. x,y, width, height +******************************************************************************/ +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; +} + +/****************************************************************************** + AddButton - Allocate space for and add the button to the bottom +******************************************************************************/ +int AddButton(ButtonArray *array, char *title, Picture *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); +} + +/****************************************************************************** + UpdateButton - Change the name/stae of a button +******************************************************************************/ +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; +} + +/* ------------------------------------------------------------------------- + UpdateButtonPicture - Change the picture of a button + ------------------------------------------------------------------------- */ +int UpdateButtonPicture(ButtonArray *array, int butnum, Picture *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; +} + +/****************************************************************************** + UpdateButtonSet - Change colour set of a button between odd and even +******************************************************************************/ +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; +} + +/****************************************************************************** + UpdateButtonDesk - Change desk of a button +******************************************************************************/ +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; +} + + +/****************************************************************************** + RemoveButton - Delete a button from the list +******************************************************************************/ +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; +} + +/****************************************************************************** + find_n - Find the nth button in the list (Use internally) +******************************************************************************/ +Button *find_n(ButtonArray *array, int n) +{ + Button *temp; + int i; + + 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) +{ + if (ptr != NULL) { + if (ptr->title!=NULL) free(ptr->title); + free(ptr); + } +} + +/****************************************************************************** + FreeAllButtons - Free the whole array of buttons +******************************************************************************/ +void FreeAllButtons(ButtonArray *array) +{ +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) +{ + 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); + +} + +/****************************************************************************** + DrawButtonArray - Draw the whole array (all=1), or only those that need. +******************************************************************************/ +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++; + } + } +} + +/****************************************************************************** + SwitchButton - Alternate the state of a button +******************************************************************************/ +void SwitchButton(ButtonArray *array, int butnum) +{ + Button *btn; + + 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) +{ + 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 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) +{ + Button *temp; + + temp=find_n(array,butnum); + return temp->title; +} + +/****************************************************************************** + PrintButtons - Print the array of button names to the console. (Debugging) +******************************************************************************/ +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"); +} + +#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; +} +#endif diff --git a/app/fvwm/modules/FvwmWinList/ButtonArray.h b/app/fvwm/modules/FvwmWinList/ButtonArray.h new file mode 100644 index 000000000..628b6e21a --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/ButtonArray.h @@ -0,0 +1,51 @@ +/* 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) + */ + +/* Struct definitions */ +typedef struct button +{ + char *title; + char *truncate_title; /* valid only if truncatewidth > 0 */ + int up, needsupdate, tw, set, truncatewidth; + struct button *next; + Picture p; + long desk; +} Button; + +typedef struct +{ + int count; + Button *head,*tail; + int x,y,w,h; +} ButtonArray; + +#define MAX_COLOUR_SETS 4 + +/* Function Prototypes */ +Button *ButtonNew(char *title, Picture *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, Picture *p,int up); +int UpdateButton(ButtonArray *array, int butnum, char *title, int up); +int UpdateButtonPicture(ButtonArray *array, int butnum, Picture *p); +int UpdateButtonSet(ButtonArray *array, int butnum, int set); +void RemoveButton(ButtonArray *array, int butnum); +Button *find_n(ButtonArray *array, int n); +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); +int WhichButton(ButtonArray *array,int x, int y); +void PrintButtons(ButtonArray *array); diff --git a/app/fvwm/modules/FvwmWinList/CHANGELOG b/app/fvwm/modules/FvwmWinList/CHANGELOG new file mode 100644 index 000000000..db879f5b4 --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/CHANGELOG @@ -0,0 +1,96 @@ +March 21st, 1994: (All the patches should have been fixed/replaced by new mods) + - Changed <sys/varags.h> to <varargs.h> + - Added <ctype.h> to Mallocs.c + - Fonts now work. (Stupid me) + - Added options: + *FvwmWinListGeometry {+-}<x>{+-}x (size is ignored) + *FvwmWinListAction <action> <response> + Only Click1, Click2, Click3 are allowed as actions right now + Responses can be any Fvwm built in, or a comma seperated list of such. + (ie: '*FvwmWinListAction Click1 Iconify -1, Raise' will deiconify the + window and then raise it) + Click1 defaults to 'Iconify -1, Raise' + Click2 defaults to 'Iconify' + Click3 defaults to 'Lower' + (See config.sample for an example) + *FvwmWinListUseSkipList + Will not show the windows listed in a 'WindowListSkip' line. + *FvwmWinListNoAnchor + FvwmWinList will, by default, anchor the corner which has gravity, use + this to undo it. (btw, NW gravity and NoAnchor provide the same result. + (+x+y=NorthWest,+x-y=SouthWest,-x+y=NorthEast,-x-y=SouthEast) + This is so you can place the window list in the lower corners and + the list will not wrap past the screen edge. + +March 25st, 1994: (The patch should have be fixed/replaced by new mods) + - FvwmWinListUseIconNames + As it says, it will use the icon names instead of using the window + names. People have mentioned that some window names become to long. + - FvwmWinList now skips windows if the name in the WindowListSkip line + matches the windows name, icon name, resource name, or resource class. + (This is the same way the built-in fvwm window list works) + - Changed some code so it doesn't redraw the window so often. + - Added man page. + +April 5th, 1994: (Patches should be overtaken by this release) + - Allowed FvwmWinList to be started up with an arguemnt 'Transient' to allow + it to work like the build in window list. Right now if you use it in + transient mode it will only execute the command for Click1. Looking + for suggestions about using other buttons. Was considering using + modifiers (ie. Shift means button 2, etc) + - FvwmWinList now uses MWMDecorHints. (Makes the 'Transient' mode look good) + - Buttons now stay down until you actually release the button. You can click + and hold the button down and move across the buttons and the will go up + and down as to enter leave the area. Actions are performed on button + release and not on press. + - FvwmWinList will unmap itself if it has no windows to display and will + remap itself when a new window it can display is opened. If there + are no windows to display and you are using it in transient mode, it + will not come up. + +April 16th, 1994: + - Patched to use the new style way of WindowSkipList + - Cleaned up some definitions + +May 8th, 1994: This patch replaces the April 16th patch + - Re-did the patch because of bad hunk. + - Added strcasecmp for those who have 'NEED_STRCASECMP' defined. + - Fixed WinList drifting problem with BorderWidth of 0 + +May 9th, 1994: + - Removed support for the old style of WindowSkipList, you must use Styles. + - Hopefully, the above will speed up processing of the list from fvwm and + it will not hang. Please let me know if you still have problems, you + might. + +May, 1996: + * Modifications by Don Mahurin, May 1996 + * Modifications Done to Add Title Icon support, focus highlighting and + Current Desk Only Option + * 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.(So if FvwmWinListShowCurrentWindow is set + * moving a window does not move it on the WinList + + * There seems to be something incosistant about Resizing and the value given + * back as win_x, win_y with fvwm. SEE RESIZE_BUG_HACK in the code for my work + * around. Ok, Ill tell you about it: + XMoveResizeWindow sometimes assumes the x,y you pass it includes the + border width, other times it doesnt. Specific to the program, When I + am only opening closing/minimizing Windows in the same desktop, borders + have to be added when adjusting. But when I Adjust the window when + changing Desktops, + I have to remove the border width( and a fudge factor). + + * Don Mahurin (dmahurin@donet.com) + +Sept.23, 1996. + + - Ported MiniIcon changes to Fvwm2. Uses MiniIcon, MINI_ICON, not TITLE_ICONS ... + + - Don Mahurin + - dmahurin@donet.com + diff --git a/app/fvwm/modules/FvwmWinList/Colors.c b/app/fvwm/modules/FvwmWinList/Colors.c new file mode 100644 index 000000000..15b2158de --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/Colors.c @@ -0,0 +1,49 @@ +/* Part of the 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 were originally part of the GoodStuff + * and FvwmIdent modules for Fvwm, so there copyrights are also included: + * + * 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 <stdio.h> +#include <X11/Xlib.h> +#include "Colors.h" + + +extern Display *dpy; +extern Window Root; + +/**************************************************************************** + Loads a single color +*****************************************************************************/ +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; +} + + +void nocolor(char *a, char *b) +{ + fprintf(stderr,"FvwmWinList: can't %s %s\n", a,b); +} diff --git a/app/fvwm/modules/FvwmWinList/Colors.h b/app/fvwm/modules/FvwmWinList/Colors.h new file mode 100644 index 000000000..0a3618666 --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/Colors.h @@ -0,0 +1,19 @@ +/* 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: + * + * 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 <X11/Intrinsic.h> + +/* Function Prototypes */ +Pixel GetColor(char *name); +Pixel GetHilite(Pixel background); +Pixel GetShadow(Pixel background); +void nocolor(char *a, char *b); + diff --git a/app/fvwm/modules/FvwmWinList/FvwmWinList.1 b/app/fvwm/modules/FvwmWinList/FvwmWinList.1 new file mode 100644 index 000000000..60f93b6a0 --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/FvwmWinList.1 @@ -0,0 +1,162 @@ +.\" $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 +.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. + +.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. + +.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. + +.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. + +.SH CONFIGURATION OPTIONS +The following options can be placed in the .fvwmrc file + +.IP "*FvwmWinListGeometry \fI{+-}<X>{+-}<Y>\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) + +.IP "*FvwmWinListFont \fIfont\fP" +Specifies the font to be used for labeling the buttons. + +.IP "*FvwmWinListFore \fIcolor\fP" +Specifies the color to use for the button names. + +.IP "*FvwmWinListBack \fIcolor\fP" +Specifies the color for 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. + +.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. + +.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. + +.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. + +.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. + +.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. + +.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. + +.SH SAMPLE CONFIGURATION +The following are excepts from a .fvwmrc file which describe FvwmWinList +initialization commands: + +.nf +.sp +XCOMM####### +XCOMM Pop up the window list in tranient mode on button 3 press & hold + +Mouse 3 R A Module "FvwmWinList" FvwmWinList Transient + +XCOMM######################### Window-Lister ############################### +*FvwmWinListBack DarkOliveGreen +*FvwmWinListFore PaleGoldenRod +*FvwmWinListFont -*-new century schoolbook-bold-r-*-*-*-120-*-*-*-*-*-* +*FvwmWinListAction Click1 Iconify -1,Raise +*FvwmWinListAction Click2 Iconify +*FvwmWinListAction Click3 Module "FvwmIdent" FvwmIdent +*FvwmWinListUseSkipList +*FvwmWinListUseIconNames +*FvwmWinListGeometry -50-85 +*FvwmWinListMinWidth 70 +*FvwmWinListMaxWidth 120 +XCOMM I prefer the text centered +XCOMM*FvwmWinListLeftJustify +XCOMM I like it achored +XCOMM*FvwmWinListNoAnchor + +.sp +.fi + +.SH AUTHOR +Mike Finger (mfinger@mermaid.micro.umn.edu) + (Mike_Finger@atk.com) + (doodman on IRC, check the #linux channel) +Various Patches by + John Heidemann <johnh@ficus.CS.UCLA.EDU> and + Jason L Tibbitts <tibbs@tcamc.uh.edu>. diff --git a/app/fvwm/modules/FvwmWinList/FvwmWinList.c b/app/fvwm/modules/FvwmWinList/FvwmWinList.c new file mode 100644 index 000000000..9fb6aaa39 --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/FvwmWinList.c @@ -0,0 +1,1076 @@ +/* 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, origonal 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. + + * 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 FALSE 0 + +#ifndef NO_CONSOLE +#define NO_CONSOLE +#endif + +#define YES "Yes" +#define NO "No" + +#include "config.h" + +#include <stdio.h> +#include <signal.h> +#include <fcntl.h> +#include <string.h> +#include <sys/wait.h> +#include <sys/time.h> +#include <stdarg.h> + +#if HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif + +#include <unistd.h> +#include <ctype.h> + +#ifdef HAVE_SYS_BSDTYPES_H +#include <sys/bsdtypes.h> /* Saul */ +#endif + +#include <stdlib.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/Xproto.h> +#include <X11/Xatom.h> +#include <X11/Intrinsic.h> +#include <X11/cursorfont.h> + +#include "../../fvwm/module.h" + +#include "FvwmWinList.h" +#include "ButtonArray.h" +#include "List.h" +#include "Colors.h" +#include "Mallocs.h" + +#define GRAB_EVENTS (ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|EnterWindowMask|LeaveWindowMask) + +#define SomeButtonDown(a) ((a)&Button1Mask||(a)&Button2Mask||(a)&Button3Mask) + +/* File type information */ +FILE *console; +int fd_width; +int Fvwm_fd[2]; +int x_fd; + +/* X related things */ +Display *dpy; +Window Root, win; +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]; +XFontStruct *ButtonFont; +int fontheight; +static Atom wm_del_win; +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; +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 *font_string = "fixed"; +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); + +/*************************************************************************** + * TerminateHandler - reentrant signal handler that ends the main event loop + ***************************************************************************/ +static RETSIGTYPE TerminateHandler(int sig) +{ + isTerminated = True; +} + +int ItemCountD(List *list ) +{ + if(!ShowCurrentDesk) + return ItemCount(list); + /* else */ + return ItemCountDesk(list, CurrentDesk); + +} + +/****************************************************************************** + Main - Setup the XConnection,request the window list and loop forever + Based on main() from FvwmIdent: + Copyright 1994, Robert Nation and Nobutaka Suzuki. +******************************************************************************/ +int main(int argc, char **argv) +{ + char *temp, *s; +#ifdef HAVE_SIGACTION + 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); + } + + + if ((argc==7)&&(!strcasecmp(argv[6],"Transient"))) Transient=1; + + Fvwm_fd[0] = atoi(argv[1]); + Fvwm_fd[1] = atoi(argv[2]); + +#ifdef HAVE_SIGACTION +#ifdef SA_INTERRUPT + sigact.sa_flags = SA_INTERRUPT; +#else + sigact.sa_flags = 0; +#endif + sigemptyset(&sigact.sa_mask); + sigact.sa_handler = TerminateHandler; + sigaction(SIGPIPE, &sigact, NULL); + sigaction(SIGTERM, &sigact, NULL); +#else + signal(SIGPIPE, TerminateHandler); + signal(SIGTERM, TerminateHandler); +#ifdef HAVE_SIGINTERRUPT + siginterrupt(SIGPIPE, True); + siginterrupt(SIGTERM, True); +#endif +#endif + + /* Parse the config file */ + ParseConfig(); + + /* Setup the XConnection */ + StartMeUp(); + XSetErrorHandler(ErrorHandler); + + InitPictureCMap(dpy, Root); + + InitArray(&buttons,0,0,win_width, fontheight+6); + InitList(&windows); + + fd_width = GetFdWidth(); + + /* 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 | +#ifdef MINI_ICONS + M_MINI_ICON | +#endif + M_STRING); + + SendFvwmPipe("Send_WindowList",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) +{ +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 */ +} + +/****************************************************************************** + ReadFvwmPipe - Read a single message from the pipe from Fvwm + Originally Loop() from FvwmIdent: + Copyright 1994, Robert Nation and Nobutaka Suzuki. +******************************************************************************/ +void ReadFvwmPipe(void) +{ + unsigned long header[HEADER_SIZE],*body; + + if(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) +{ + int redraw=0,i; + long flags; + char *name,*string; + static int current_focus=-1; + + Picture 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; + +#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; +#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); +} + +/****************************************************************************** + SendFvwmPipe - Send a message back to fvwm + Based on SendInfo() from FvwmIdent: + Copyright 1994, Robert Nation and Nobutaka Suzuki. +******************************************************************************/ +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; + } +} + +/*********************************************************************** + Detected a broken pipe - time to exit + Based on DeadPipe() from FvwmIdent: + Copyright 1994, Robert Nation and Nobutaka Suzuki. + **********************************************************************/ +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); +} + +/****************************************************************************** + WaitForExpose - Used to wait for expose event so we don't draw too early +******************************************************************************/ +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; + } + } +} + +/****************************************************************************** + RedrawWindow - Update the needed lines and erase any old ones +******************************************************************************/ +void RedrawWindow(int force) +{ + DrawButtonArray(&buttons, force); + if (XQLength(dpy) && !force) LoopOnEvents(); +} + +/****************************************************************************** + ConsoleMessage - Print a message on the console. Works like printf. +******************************************************************************/ +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); +#endif +} + +/****************************************************************************** + OpenConsole - Open the console as a way of sending messages +******************************************************************************/ +int OpenConsole(void) +{ +#ifndef NO_CONSOLE + if ((console=fopen("/dev/console","w"))==NULL) { + fprintf(stderr,"%s: cannot open console\n",Module); + return 0; + } +#endif + return 1; +} + +/****************************************************************************** + ParseConfig - Parse the configuration file fvwm to us to use + Based on part of main() from FvwmIdent: + Copyright 1994, Robert Nation and Nobutaka Suzuki. +******************************************************************************/ +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; + } + GetConfigLine(Fvwm_fd,&tline); + } +} + +/****************************************************************************** + LoopOnEvents - Process all the X events we get +******************************************************************************/ +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; + } + } +} + + +/****************************************************************************** + 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 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; +} + +/****************************************************************************** + AdjustWindow - Resize the window according to maxwidth by number of buttons +******************************************************************************/ +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;i<total;i++) + { + temp=ItemName(&windows,i); + if(temp != NULL) + { + tw=10+XTextWidth(ButtonFont,temp,strlen(temp)); + tw+=XTextWidth(ButtonFont,"()",2); + +#ifdef MINI_ICONS + tw+=14; /* for title icon */ /* Magic Number ? */ +#endif + + 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 *ptr; + ptr=safemalloc(strlen(string)+3); + *ptr = '\0'; + if (flags&ICONIFIED) strcpy(ptr,"("); + strcat(ptr,string); + if (flags&ICONIFIED) strcat(ptr,")"); + return ptr; +} + +/****************************************************************************** + LinkAction - Link an response to a users action +******************************************************************************/ +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]); +} + +/****************************************************************************** + MakeMeWindow - Create and setup the window we will need +******************************************************************************/ +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); + } + +} + +/****************************************************************************** + StartMeUp - Do X initialization things +******************************************************************************/ +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 ((ButtonFont=XLoadQueryFont(dpy,font_string))==NULL) + { + if ((ButtonFont=XLoadQueryFont(dpy,"fixed"))==NULL) exit(1); + } + + fontheight = ButtonFont->ascent+ButtonFont->descent; + + win_width=XTextWidth(ButtonFont,"XXXXXXXXXXXXXXX",10); + +} + +/****************************************************************************** + ShutMeDown - Do X client cleanup +******************************************************************************/ +void ShutMeDown(void) +{ + FreeList(&windows); + FreeAllButtons(&buttons); +/* XFreeGC(dpy,graph);*/ + if (WindowIsUp) XDestroyWindow(dpy,win); + XCloseDisplay(dpy); +} + +/****************************************************************************** + ChangeWindowName - Self explanitory + Original work from FvwmIdent: + Copyright 1994, Robert Nation and Nobutaka Suzuki. +******************************************************************************/ +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); +} + +/************************************************************************** + * + * Sets mwm hints + * + *************************************************************************/ +/* + * Now, if we (hopefully) have MWW - compatible window manager , + * say, mwm, ncdwm, or else, we will set useful decoration style. + * Never check for MWM_RUNNING property.May be considered bad. + */ + +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); + } +} + +/************************************************************************ + X Error Handler +************************************************************************/ +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; +} + diff --git a/app/fvwm/modules/FvwmWinList/FvwmWinList.h b/app/fvwm/modules/FvwmWinList/FvwmWinList.h new file mode 100644 index 000000000..9497b9d2b --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/FvwmWinList.h @@ -0,0 +1,104 @@ +#include "fvwmlib.h" + +/* 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 header 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. */ + +#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; +} PropMotifWmHints; + +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) + +/* 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) + +/* 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 + +/* 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 PROP_MOTIF_WM_HINTS_ELEMENTS 4 +#define PROP_MWM_HINTS_ELEMENTS PROP_MOTIF_WM_HINTS_ELEMENTS + +/* default values for configuration parameters */ +#define DEFMAXWIDTH 10000 +#define DEFMINWIDTH 0 + +/************************************************************************* + Subroutine Prototypes +**************************************************************************/ +void MainEventLoop(void); +void ReadFvwmPipe(void); +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))); +int OpenConsole(void); +void ParseConfig(void); +void LoopOnEvents(void); +void AdjustWindow(void); +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); + +int ErrorHandler(Display *d, XErrorEvent *event); diff --git a/app/fvwm/modules/FvwmWinList/Imakefile b/app/fvwm/modules/FvwmWinList/Imakefile new file mode 100644 index 000000000..5e7857cdf --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/Imakefile @@ -0,0 +1,12 @@ +XCOMM $OpenBSD: Imakefile,v 1.1.1.1 2006/11/26 10:53:56 matthieu Exp $ + +FVWMTOP=../.. +#include "../../Fvwm.tmpl" + +SRCS= ButtonArray.c Colors.c FvwmWinList.c List.c Mallocs.c +OBJS= ButtonArray.o Colors.o FvwmWinList.o List.o Mallocs.o + +DEPLIBS= $(FVWMLIB) $(DEPXPMLIB) $(DEPXLIB) +LOCAL_LIBRARIES= $(FVWMLIB) $(XPMLIB) $(XLIB) + +FvwmComplexModuleTarget(FvwmWinList) diff --git a/app/fvwm/modules/FvwmWinList/List.c b/app/fvwm/modules/FvwmWinList/List.c new file mode 100644 index 000000000..a6d5b1ac1 --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/List.c @@ -0,0 +1,325 @@ +/* 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 <stdio.h> +#include <stdlib.h> +#include "List.h" +#include "Mallocs.h" +#include "../../fvwm/module.h" + +#include <X11/Xmd.h> +#include "FvwmWinList.h" + +/****************************************************************************** + InitList - Initialize the list +******************************************************************************/ +void InitList(List *list) +{ + 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) +{ +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++; +} + +/****************************************************************************** + FindItem - Find the item in the list matching the 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; +} + +/****************************************************************************** + FindItemDesk - Find the item in the list matching the id, and desk id +******************************************************************************/ +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; +} + + +/****************************************************************************** + UpdateItem - Update the item in the list, setting name & flags as necessary. +******************************************************************************/ +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; +} + +/****************************************************************************** + 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 not found +******************************************************************************/ +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; +} + +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; +} + +/****************************************************************************** + FreeItem - Frees allocated space for an Item +******************************************************************************/ +void FreeItem(Item *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) +{ + 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) +{ + 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) +{ +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) ? "<null>" : temp->name, + temp->flags); + } +} + +/****************************************************************************** + ItemName - Return the name of an Item +******************************************************************************/ +char *ItemName(List *list, int n) +{ + 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) +{ + Item *temp; + + for(temp=list->head; temp != NULL && id!=temp->id; temp=temp->next); + if (temp==NULL) + return -1; + + else return temp->flags; +} + +/****************************************************************************** + ItemDesk - Return the desk for an item +******************************************************************************/ +long ItemDesk(List *list, long id) +{ + Item *temp; + + for(temp=list->head;temp!=NULL && id!=temp->id;temp=temp->next); + + 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) +{ + 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) +{ + return list->count; +} + +/****************************************************************************** + ItemCountDesk - Return the number of items inthe list, with desk desk +******************************************************************************/ + +int ItemCountDesk(List *list, long desk) +{ + Item *temp; + int count=0; + +/*return list->count;*/ + + for(temp=list->head; + temp != NULL; + temp = temp->next + ) + { + if(temp->desk == desk) + count++; + } + + return count; +} + +/****************************************************************************** + ItemID - Return the ID of the item in the list. +******************************************************************************/ +long ItemID(List *list, int n) +{ + 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) +{ + 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); +} + diff --git a/app/fvwm/modules/FvwmWinList/List.h b/app/fvwm/modules/FvwmWinList/List.h new file mode 100644 index 000000000..2467d134f --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/List.h @@ -0,0 +1,51 @@ +/* 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; +} Item; + +typedef struct +{ + Item *head,*tail; + int count; +} List; + +/* Function Prototypes */ +void InitList(List *list); +void AddItem(List *list, long id, long flags, long desk ); +int FindItem(List *list, long id); +int FindItemDesk(List *list, long id, long desk); + +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); +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 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); diff --git a/app/fvwm/modules/FvwmWinList/Makefile b/app/fvwm/modules/FvwmWinList/Makefile new file mode 100644 index 000000000..f0c03aab1 --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/Makefile @@ -0,0 +1,14 @@ +# $Xenocara: Makefile,v 1.1 2006/04/17 20:17:13 matthieu Exp $ + +.include "../Makefile.inc" + +.PATH: ${DIST}/modules/FvwmWinList + +PROG= FvwmWinList +SRCS= ButtonArray.c Colors.c FvwmWinList.c List.c Mallocs.c + +LDADD+= -lXpm -lX11 +BINDIR= ${FVWMLIBDIR} + +.include <bsd.prog.mk> +.include <bsd.xorg.mk> diff --git a/app/fvwm/modules/FvwmWinList/Mallocs.c b/app/fvwm/modules/FvwmWinList/Mallocs.c new file mode 100644 index 000000000..26126ad25 --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/Mallocs.c @@ -0,0 +1,58 @@ +/* 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 <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <sys/time.h> +#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); +} + + diff --git a/app/fvwm/modules/FvwmWinList/Mallocs.h b/app/fvwm/modules/FvwmWinList/Mallocs.h new file mode 100644 index 000000000..a1ea87cce --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/Mallocs.h @@ -0,0 +1,25 @@ +/* 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); + diff --git a/app/fvwm/modules/FvwmWinList/README b/app/fvwm/modules/FvwmWinList/README new file mode 100644 index 000000000..bfb946b3a --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/README @@ -0,0 +1,114 @@ +If you have read the a previous README on this, you may want to skip to the +CHANGELOG. This file is very familiar to the last README. + +Well, here is a summary of what it will do (* = new): + - All memory in managed dynamically by linked lists, keeping in the spirit + of Fvwm to use as little memory as possible. + - Display all windows that Fvwm knows about in Fvwm style buttons + - Iconifying a window will place () around its name in the list + - Can be nicely shutdown by typing 'Q' or 'q' inside the window + - FvwmWinListGeometry {+-}<x>{+-}x (size is ignored) + - FvwmWinListAction <action> <response> + Only Click1, Click2, Click3 are allowed as actions right now + Responses can be any Fvwm built in, or a comma seperated list of such. + (ie: '*FvwmWinListAction Click1 Iconify -1, Raise' will deiconify the + window and then raise it) + Click1 defaults to 'Iconify -1, Raise' + Click2 defaults to 'Iconify' + Click3 defaults to 'Lower' + (See config.sample for an example) + - FvwmWinListUseSkipList + Will not show the windows listed with a 'WindowListSkip' style. + - FvwmWinListNoAnchor + FvwmWinList will, by default, anchor the corner which has gravity, use + this to undo it. (btw, NW gravity and NoAnchor provide the same result. + (+x+y=NorthWest,+x-y=SouthWest,-x+y=NorthEast,-x-y=SouthEast) + This is so you can place the window list in the lower corners and + the list will not wrap past the screen edge. + - FvwmWinListUseIconNames + As it says, it will use the icon names instead of using the window + names. People have mentioned that some window names become to long. + - Allowed FvwmWinList to be started up with an arguemnt 'Transient' to allow + it to work like the build in window list. Right now if you use it in + transient mode it will only execute the command for Click1. Looking + for suggestions about using other buttons. Was considering using + modifiers (ie. Shift means button 2, etc) + - FvwmWinList now uses MWMDecorHints. (Makes the 'Transient' mode look good) + - Buttons now stay down until you actually release the button. You can click + and hold the button down and move across the buttons and the will go up + and down as to enter leave the area. Actions are performed on button + release and not on press. + - FvwmWinList will unmap itself if it has no windows to display and will + remap itself when a new window it can display is opened. If there + are no windows to display and you are using it in transient mode, it + will not come up. + +I have only run this under Linux on my 386/40 with 8megs, please let me know +if you experience problems with compiling, running, or performance. I want +to tune it to run as efficient as possible, later in life. + +Now, the things I still want to do with it. If you have suggestions, please +send them to me, want to make this as useful as possible. + +To do: (in no particular order) + - Add the following configurable options: + - FvwmWinlistAction <action> <response> + Add more actions, like press, release, motion, 2x click, slide, etc., + instead of just Click<x> + - FvwmWinlistOrientaion (down|across) + Should the buttons be a vertical or a horizontal list + - FvwmWinlistMaxWidth <x> + Where x is the max pixel width of the window. + - FvwmWinlistTooLong (wrap|truncate|initials) + What to do if the names are too long. (assuming you set MaxWidth) + - Allow the user to setup what is in the Op's and Detail's menu + - Possible allow diffent fonts/colors for submenus. + - Rob mentioned some people would like icons in the list if the window + if iconified. I personally like the (), although I am a but biased. + Let me know what you think/want, I will try. + - Place a small 3-D pixmap/bitmap next-to/around the windows that are + iconified instead of the (). + - Like to allow resizing of the window and have the buttons match the window + (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) + +I am open to, actually I am trolling for, suggestions/improvments/ideas/rags +on this. + +Here is a list of files included in the tar file: + +ButtonArray.c +ButtonArray.h +CHANGELOG +Colors.c +Colors.h +FvwmWinList.README +FvwmWinList.c +FvwmWinList.h +Imakefile +List.c +List.h +Mallocs.c +Mallocs.h +config.sample +wild.c + +You can unpack it by: + +cd /foo/fvwm/modules +gzip -dc FvwmWinList-0.1.tar.gz | tar xf - + +That will unpack the source into /foo/fvwm/modules/FvwmWinList. + + +If you want a binary distribution or diffs, let me know. + +Enjoy, +Mike +mfinger@mermaid.micro.umn.edu or Mike_Finger@atk.com diff --git a/app/fvwm/modules/FvwmWinList/config.sample b/app/fvwm/modules/FvwmWinList/config.sample new file mode 100644 index 000000000..003fdc5e0 --- /dev/null +++ b/app/fvwm/modules/FvwmWinList/config.sample @@ -0,0 +1,17 @@ +################### +# Pop up the window list on click and hold of mouse button 3 + +Mouse 3 R A Module "FvwmWinList" FvwmWinList Transient + +########################## Window-Lister ############################### +*FvwmWinListBack DarkOliveGreen +*FvwmWinListFore PaleGoldenRod +*FvwmWinListFont -*-new century schoolbook-bold-r-*-*-*-120-*-*-*-*-*-* +*FvwmWinListAction Click1 Focus,Iconify -1,Focus +*FvwmWinListAction Click2 Iconify +*FvwmWinListAction Click3 Module "FvwmIdent" FvwmIdent +*FvwmWinListUseSkipList +*FvwmWinListUseIconNames +*FvwmWinListGeometry -50-85 +# I like it achored +#*FvwmWinListNoAnchor |