2 /* FvwmTaskBar Module for Fvwm.
4 * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or
7 * The functions in this source file are the original work of Mike Finger.
9 * No guarantees or warantees or anything are provided or implied in any way
10 * whatsoever. Use this program at your own risk. Permission to use this
11 * program for any purpose is given, as long as the copyright is kept intact.
15 /* This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "libs/Module.h"
35 #include "FvwmTaskBar.h"
39 extern ModuleArgs
*module
;
42 InitList - Initialize the list
44 void InitList(List
*list
)
46 list
->head
=list
->tail
=NULL
;
51 AddItem - Allocates spaces for and appends an item to the list
53 void AddItem(List
*list
, long id
, ConfigWinPacket
*cfgpacket
,
57 new=(Item
*)safemalloc(sizeof(Item
));
60 memcpy(&new->flags
, &cfgpacket
->flags
, sizeof(new->flags
));
63 memset((void *)&(new->p
), 0, sizeof(FvwmPicture
));
65 if (list
->tail
==NULL
) list
->head
=list
->tail
=new;
74 AddItemName - Allocates spaces for and appends an item to the list
76 void AddItemName(List
*list
, char *string
, int iconified
)
80 new = (Item
*)safemalloc(sizeof(Item
));
83 UpdateString(&new->name
, string
);
84 SET_ICONIFIED(new,iconified
);
87 if (list
->tail
== NULL
)
88 list
->head
= list
->tail
= new;
91 list
->tail
->next
= new;
99 FindItem - Find the item in the list matching the id
101 int FindItem(List
*list
, long id
)
105 for(temp
=list
->head
;temp
!=NULL
&& temp
->id
!=id
;temp
=temp
->next
);
112 FindNameItem - Find the item in the list matching the string
114 int FindNameItem(List
*list
, char *string
)
119 temp
!=NULL
&& strcmp(temp
->name
,string
) != 0;
121 if (temp
==NULL
) return -1;
126 UpdateItem* - Update the item in the list
129 int UpdateItemName(List
*list
, long id
, char *string
)
132 for(temp
=list
->head
;temp
!=NULL
&& id
!=temp
->id
;temp
=temp
->next
);
133 if (temp
==NULL
) return -1;
134 UpdateString(&temp
->name
,string
);
138 int UpdateItemIconifiedFlag(List
*list
, long id
, int iconified
)
141 for(temp
=list
->head
;temp
!=NULL
&& id
!=temp
->id
;temp
=temp
->next
);
142 if (temp
==NULL
) return -1;
143 SET_ICONIFIED(temp
,iconified
);
147 int UpdateItemGSFRFlags(List
*list
, ConfigWinPacket
*cfgpacket
)
150 for(temp
=list
->head
;temp
!=NULL
&& cfgpacket
->w
!=temp
->id
;temp
=temp
->next
);
151 if (temp
==NULL
) return -1;
152 temp
->flags
= cfgpacket
->flags
;
156 int UpdateItemIndexDesk(List
*list
, int i
, long desk
)
159 for(temp
=list
->head
;temp
!=NULL
&& temp
->count
!=i
;temp
=temp
->next
);
160 if (temp
==NULL
) return -1;
165 int UpdateNameItem(List
*list
, char *string
, long id
, int iconified
)
170 temp
!=NULL
&& strcmp(temp
->name
,string
) != 0;
172 if (temp
==NULL
) return -1;
174 if (id
!= -1) temp
->id
= id
;
175 if (iconified
!= -1) SET_ICONIFIED(temp
,iconified
);
180 int UpdateItemIndexGeometry(List
*list
, int i
, rectangle
*new_g
)
183 for(temp
=list
->head
;temp
!=NULL
&& temp
->count
!=i
;temp
=temp
->next
);
184 if (temp
==NULL
) return -1;
185 temp
->win_g
= *new_g
;
190 FreeItem - Frees allocated space for an Item
192 void FreeItem(Item
*ptr
)
195 if (ptr
->name
!=NULL
) free(ptr
->name
);
201 DeleteItem - Deletes an item from the list
203 int DeleteItem(List
*list
,long id
)
207 if (list
->head
==NULL
) return -1;
208 if (list
->head
->id
==id
) {
210 temp
=list
->head
=list
->head
->next
;
213 for(temp
=list
->head
,temp2
=temp
->next
; temp2
; temp2
=temp2
->next
) {
218 if (temp2
== NULL
) return -1;
219 temp
->next
=temp2
->next
;
222 if (temp2
==list
->tail
) list
->tail
=temp
;
232 FreeList - Free the entire list of Items
234 void FreeList(List
*list
)
237 for(temp
=list
->head
;temp
!=NULL
;)
247 PrintList - Print the list of item to stderr. (Debugging)
249 void PrintList(List
*list
)
252 fprintf(stderr
,"%s List of Items:\n", module
->name
);
253 fprintf(stderr
," %10s %-15s %-15s %-15s %-15s Flgs\n","ID","Name","I-Name",
255 fprintf(stderr
," ---------- --------------- --------------- --------------- --------------- ----\n");
256 for(temp
=list
->head
;temp
!=NULL
;temp
=temp
->next
) {
257 fprintf(stderr
," %10ld %-15.15s\n",temp
->id
,
258 (temp
->name
==NULL
) ? "<null>" : temp
->name
);
263 ItemName - Return the name of an Item
265 char *ItemName(List
*list
, int n
)
268 for(temp
=list
->head
;temp
!=NULL
&& temp
->count
!=n
;temp
=temp
->next
);
269 if (temp
==NULL
) return NULL
;
274 IsItemIndexIconified - Say if an item is iconified
276 int IsItemIconified(List
*list
, long id
)
279 for(temp
=list
->head
;temp
!=NULL
&& temp
->id
!=id
;temp
=temp
->next
);
280 if (temp
==NULL
) return -1;
281 return IS_ICONIFIED(temp
);
285 IsItemIndexIconified - Say if an item of index i is iconified
287 int IsItemIndexIconified(List
*list
, int i
)
290 for(temp
=list
->head
;temp
!=NULL
&& temp
->count
!=i
;temp
=temp
->next
);
291 if (temp
==NULL
) return -1;
292 return IS_ICONIFIED(temp
);
296 IsItemIndexSticky - Say if an item of index i is sticky
298 int IsItemIndexSticky(List
*list
, int i
)
301 for(temp
=list
->head
;temp
!=NULL
&& temp
->count
!=i
;temp
=temp
->next
);
302 if (temp
==NULL
) return -1;
303 return (IS_STICKY_ACROSS_DESKS(temp
) ||
304 (IS_ICONIFIED(temp
) && IS_ICON_STICKY_ACROSS_DESKS(temp
)));
308 IsItemIndexSkipWindowList - Say if an item of index i is in the skip list
310 int IsItemIndexSkipWindowList(List
*list
, int i
)
313 for(temp
=list
->head
;temp
!=NULL
&& temp
->count
!=i
;temp
=temp
->next
);
314 if (temp
==NULL
) return -1;
315 return DO_SKIP_WINDOW_LIST(temp
);
319 IsItemIndexIconSuppressed - Say if an item has a no icon style
321 int IsItemIndexIconSuppressed(List
*list
, int i
)
324 for(temp
=list
->head
;temp
!=NULL
&& temp
->count
!=i
;temp
=temp
->next
);
325 if (temp
==NULL
) return -1;
326 return IS_ICON_SUPPRESSED(temp
);
330 ItemCount - Return the number of items inthe list
332 int ItemCount(List
*list
)
338 ItemID - Return the ID of the item in the list.
340 long ItemID(List
*list
, int n
)
343 for(temp
=list
->head
;temp
!=NULL
&& temp
->count
!=n
;temp
=temp
->next
);
344 if (temp
==NULL
) return -1;
349 CopyItem - Copy an item from one list to another
351 void CopyItem(List
*dest
, List
*source
, int n
)
354 ConfigWinPacket cfgpkt
;
356 for(temp
=source
->head
;temp
!=NULL
&& temp
->count
!=n
;temp
=temp
->next
);
357 if (temp
==NULL
) return;
358 memcpy(&cfgpkt
.flags
, &temp
->flags
, sizeof(cfgpkt
.flags
));
359 AddItem(dest
, temp
->id
, &cfgpkt
,temp
->Desk
,temp
->count
);
360 UpdateItemName(dest
,temp
->id
,temp
->name
);
361 DeleteItem(source
,temp
->id
);
365 UpdateItemPicture - Adds the picture information in the list
367 void UpdateItemPicture(List
*list
, int n
, FvwmPicture
*p
)
371 for (temp
=list
->head
;temp
&& temp
->count
!=n
;temp
=temp
->next
);
372 if (temp
==NULL
) return;
375 temp
->p
.picture
= p
->picture
;
376 temp
->p
.mask
= p
->mask
;
377 temp
->p
.alpha
= p
->alpha
;
378 temp
->p
.width
= p
->width
;
379 temp
->p
.height
= p
->height
;
380 temp
->p
.depth
= p
->depth
;
384 temp
->p
.picture
= None
;
386 temp
->p
.alpha
= None
;
394 GetDeskNumber - Returns the desknumber of the item
396 int GetDeskNumber(List
*list
, int n
, long *Desk
)
400 for (temp
=list
->head
;temp
&& temp
->count
!=n
;temp
=temp
->next
);
401 if (temp
==NULL
) return 0;
407 GetItemPicture - Returns the picture
409 FvwmPicture
*GetItemPicture(List
*list
, int n
)
413 for (temp
=list
->head
;temp
&& temp
->count
!=n
;temp
=temp
->next
);
414 if (temp
==NULL
) return 0;
419 GetItemGeometry - returns a pointer to the internal geometry rectangle
421 int GetItemGeometry(List
*list
, int n
, rectangle
**r
)
425 for (temp
=list
->head
;temp
&& temp
->count
!=n
;temp
=temp
->next
);
426 if (temp
==NULL
) return 0;