2 /* FvwmWinList 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.
13 * Things to do: Convert to C++ (In Progress)
16 /* This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "FvwmWinList.h"
37 #include "libs/Module.h"
38 #include "fvwm/fvwm.h"
40 extern long CurrentDesk
;
41 extern int ShowCurrentDesk
;
42 extern int UseSkipList
;
45 InitList - Initialize the list
47 void InitList(List
*list
)
49 list
->head
=list
->tail
=NULL
;
54 AddItem - Allocates spaces for and appends an item to the list
56 /*void AddItem(List *list, long id,long flags, long desk)*/
57 void AddItem(List
*list
, ConfigWinPacket
*cfgpacket
)
60 new=(Item
*)safemalloc(sizeof(Item
));
63 new->flags
=cfgpacket
->flags
;
64 new->desk
=cfgpacket
->desk
;
67 if (list
->tail
==NULL
) list
->head
=list
->tail
=new;
76 ReorderList - Make the list order matcht the internal fvwm winlist
77 FlipFocus is False when the Focus command has been used, True for all other
78 cases of Focus change.
79 If true the item is plucked from the list and placed at the start
80 If false the list is closed into a loop, rotated around to bring id to
81 the top and then opened up into a terminated line again.
83 void ReorderList(List
*list
, long id
, long FlipFocus
)
85 Item
*temp
= list
->head
, *prev
= NULL
;
88 if (!id
) return; /* this is a NOP if id == 0 */
91 while (temp
&& i
!= id
) {
97 if (!temp
) return; /* we fell off the list */
99 /* prev is guaranteed to be !NULL */
101 /* take care of the tail of the list */
102 if (list
->tail
== temp
) list
->tail
= prev
;
104 prev
->next
= temp
->next
;
106 temp
->next
= list
->head
;
110 list
->tail
->next
= list
->head
;
111 /* rotate around by changing the list pointers */
114 /* unclose the end */
120 FindItem - Find the item in the list matching the id
122 int FindItem(List
*list
, long id
)
127 for(i
=0,temp
=list
->head
;temp
!=NULL
&& temp
->id
!=id
;i
++,temp
=temp
->next
);
128 if (temp
==NULL
) return -1;
133 FindItemVisible - Find the item which should be in winlist in the list
136 int FindItemVisible(List
*list
, long id
)
141 for(temp
=list
->head
;temp
!=NULL
&& temp
->id
!=id
;temp
=temp
->next
)
143 if (IsItemVisible(temp
)) i
++;
145 if (temp
==NULL
) return -1;
151 UpdateItem - Update the item in the list, setting name & flags as necessary.
153 int UpdateItemName(List
*list
, long id
, char *string
)
158 for(i
=0,temp
=list
->head
;temp
!=NULL
&& id
!=temp
->id
;i
++,temp
=temp
->next
);
159 if (temp
==NULL
) return -1;
160 UpdateString(&temp
->name
, string
);
165 UpdateItemDesk - Update the item in the list, setting desk as necessary.
166 returns 1 if desk was updated,
167 returns 0, if not changed
168 returns -1 if not found
170 int UpdateItemDesk(List
*list
, ConfigWinPacket
*cfgpacket
)
174 for(temp
=list
->head
;temp
!= NULL
&& cfgpacket
->w
!=temp
->id
;temp
=temp
->next
);
175 if (temp
==NULL
) return -1;
176 if(temp
->desk
!= cfgpacket
->desk
)
178 temp
->desk
= cfgpacket
->desk
;
186 UpdateItemGSFRFlags - Update the GSFR flags
187 returns -1 if not found
189 int UpdateItemGSFRFlags(List
*list
, ConfigWinPacket
*cfgpacket
)
192 for(temp
=list
->head
;temp
!=NULL
&& cfgpacket
->w
!=temp
->id
;temp
=temp
->next
);
193 if (temp
==NULL
) return -1;
194 temp
->flags
= cfgpacket
->flags
;
199 FreeItem - Frees allocated space for an Item
201 void FreeItem(Item
*ptr
)
204 if (ptr
->name
!=NULL
) free(ptr
->name
);
210 DeleteItem - Deletes an item from the list
212 int DeleteItem(List
*list
,long id
)
217 if (list
->head
==NULL
) return -1;
218 if (list
->head
->id
==id
)
221 temp
=list
->head
=list
->head
->next
;
226 for(i
=0,temp
=list
->head
;temp
->next
!=NULL
&& temp
->next
->id
!=id
;
227 i
++,temp
=temp
->next
);
228 if (temp
->next
==NULL
) return -1;
230 temp
->next
=temp2
->next
;
233 if (temp2
==list
->tail
) list
->tail
=temp
;
241 FreeList - Free the entire list of Items
243 void FreeList(List
*list
)
247 for(temp
=list
->head
;temp
!=NULL
;)
257 PrintList - Print the list of item on the console. (Debugging)
259 void PrintList(List
*list
)
262 ConsoleMessage("List of Items:\n");
263 ConsoleMessage(" %10s %-15s %-15s %-15s %-15s Flgs\n",
264 "ID","Name","I-Name", "R-Name","R-Class");
265 ConsoleMessage(" ---------- --------------- --------------- --------------- --------------- ----\n");
266 for(temp
=list
->head
;temp
!=NULL
;temp
=temp
->next
) {
268 unsigned char* p
= (unsigned char*)&temp
->flags
;
269 ConsoleMessage(" %10ld %-15.15s ",
271 (temp
->name
==NULL
) ? "<null>" : temp
->name
);
272 for( i
= 0; i
< sizeof(temp
->flags
); ++i
) {
273 ConsoleMessage( "%x2", *p
++ );
275 ConsoleMessage( "\n" );
280 ItemName - Return the name of an Item
282 char *ItemName(List
*list
, int n
)
287 for(i
=0,temp
=list
->head
;temp
!=NULL
&& i
<n
;i
++,temp
=temp
->next
);
288 if (temp
==NULL
) return NULL
;
293 ItemFlags - Return the flags for an item
294 RBW - this is no longer appropriate since the Great Style Flag Rewrite, so
295 this function will just return the Item pointer. The GSFR macros know how
297 Function returns NULL if the item is not found.
299 Item
*ItemFlags(List
*list
, long id
)
303 for(temp
=list
->head
; temp
!= NULL
&& id
!=temp
->id
; temp
=temp
->next
);
310 ItemDesk - Return the desk for an item
312 long ItemDesk(List
*list
, long id
)
316 for(temp
=list
->head
;temp
!=NULL
&& id
!=temp
->id
;temp
=temp
->next
);
318 if (temp
==NULL
) return -1;
319 else return temp
->desk
;
325 ItemCount - Return the number of items in the list
327 int ItemCount(List
*list
)
333 ItemCountDesk - Return the number of items in the list which should be in
337 int ItemCountVisible(List
*list
)
342 for(temp
=list
->head
;temp
!= NULL
;temp
= temp
->next
)
344 if (IsItemVisible(temp
))
352 ItemID - Return the ID of the item in the list.
354 long ItemID(List
*list
, int n
)
359 for(i
=0,temp
=list
->head
;temp
!=NULL
&& i
<n
;i
++,temp
=temp
->next
);
360 if (temp
==NULL
) return -1;
365 CopyItem - Copy an item from one list to another
367 void CopyItem(List
*dest
, List
*source
, int n
)
371 ConfigWinPacket cfgpkt
;
373 for(i
=0,temp
=source
->head
;temp
!=NULL
&& i
<n
;i
++,temp
=temp
->next
);
374 if (temp
==NULL
) return;
375 memset(&cfgpkt
, '\0', sizeof(cfgpkt
));
376 AddItem(dest
, &cfgpkt
);
377 UpdateItemName(dest
,temp
->id
,temp
->name
);
378 DeleteItem(source
,temp
->id
);
382 IsItemVisible - Says if the item should be in winlist
384 int IsItemVisible(Item
*temp
)
386 if ((!ShowCurrentDesk
|| temp
->desk
== CurrentDesk
||
387 IS_STICKY_ACROSS_DESKS(temp
)) &&
388 (!DO_SKIP_WINDOW_LIST(temp
) || !UseSkipList
))
395 IsItemIndexVisible - Says if the item of index i in the list should be in
398 int IsItemIndexVisible(List
*list
,int n
)
403 for(i
=0,temp
=list
->head
;temp
!=NULL
&& i
<n
;i
++,temp
=temp
->next
);
404 if (temp
== NULL
) return 0;
405 if (IsItemVisible(temp
))