2 * Copyright 1989 Massachusetts Institute of Technology
4 * Permission to use, copy, modify, and distribute this software and its
5 * documentation for any purpose and without fee is hereby granted, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of M.I.T. not be used in advertising
9 * or publicity pertaining to distribution of the software without specific,
10 * written prior permission. M.I.T. makes no representations about the
11 * suitability of this software for any purpose. It is provided "as is"
12 * without express or implied warranty.
14 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
16 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 /**********************************************************************
26 * Applet region related routines
28 * 4/26/99 D. J. Hawkey Jr.
30 **********************************************************************/
41 extern void twmrc_error_prefix();
42 extern int MatchName();
44 extern void splitRegionEntry();
45 extern int roundEntryUp();
46 extern RegionEntry *prevRegionEntry();
47 extern void mergeRegionEntries();
48 extern void downRegionEntry();
49 extern RootRegion *AddRegion();
51 int appletWidth(tmp_win)
54 /* submitted by Tim Wiess - 8/23/02 */
55 if (Scr->NoBorders || LookInList(Scr->NoBorder, tmp_win->full_name, &tmp_win->class))
56 return tmp_win->attr.width;
58 return Scr->BorderWidth * 2 + tmp_win->attr.width;
61 int appletHeight(tmp_win)
64 /* submitted by Tim Wiess - 8/23/02 */
65 /* added 'tmp_win->title_height +' - djhjr - 11/11/03 */
66 if (Scr->NoBorders || LookInList(Scr->NoBorder, tmp_win->full_name, &tmp_win->class))
67 return tmp_win->title_height + tmp_win->attr.height;
69 return Scr->BorderWidth * 2 + tmp_win->title_height + tmp_win->attr.height;
72 int PlaceApplet(tmp_win, def_x, def_y, final_x, final_y)
75 int *final_x, *final_y;
81 for (rr = Scr->FirstAppletRegion; rr; rr = rr->next)
84 w = roundEntryUp (appletWidth (tmp_win), rr->stepx);
85 h = roundEntryUp (appletHeight (tmp_win), rr->stepy);
87 for (re = rr->entries; re; re = re->next)
91 /* these were 'match()' - djhjr - 10/20/01 */
92 if (MatchName(tmp_win->full_name, re->u.name, &re->re, re->type))
93 if (MatchName(tmp_win->class.res_name, re->u.name, &re->re, re->type))
94 if (MatchName(tmp_win->class.res_class, re->u.name, &re->re, re->type))
100 if (re->usedby) continue;
101 /* don't include grid spacing - djhjr - 5/22/99
102 if (re->w < w || re->h < h) continue;
104 if (re->w < appletWidth(tmp_win) || re->h < appletHeight(tmp_win))
107 splitRegionEntry (re, rr->grav1, rr->grav2, w, h);
108 re->usedby = USEDBY_TWIN;
109 re->u.twm_win = tmp_win;
111 /* evenly spaced applet placement - djhjr - 4/24/99
112 *final_x = re->x + (re->w - appletWidth (tmp_win)) / 2;
113 *final_y = re->y + (re->h - appletHeight (tmp_win)) / 2;
118 /* adjust for region gravity - djhjr 4/26/99 */
119 if (rr->grav2 == D_EAST)
120 *final_x += re->w - appletWidth(tmp_win);
121 if (rr->grav1 == D_SOUTH)
122 *final_y += re->h - appletHeight(tmp_win);
135 FindAppletEntry (tmp_win, rrp)
142 for (rr = Scr->FirstAppletRegion; rr; rr = rr->next) {
143 for (re = rr->entries; re; re=re->next)
144 if (re->u.twm_win == tmp_win) {
160 re = FindAppletEntry (tmp_win, &rr);
162 downRegionEntry(rr, re);
166 AddAppletRegion(geom, grav1, grav2, stepx, stepy)
168 int grav1, grav2, stepx, stepy;
172 rr = AddRegion(geom, grav1, grav2, stepx, stepy);
174 if (Scr->LastAppletRegion)
175 Scr->LastAppletRegion->next = rr;
176 Scr->LastAppletRegion = rr;
177 if (!Scr->FirstAppletRegion)
178 Scr->FirstAppletRegion = rr;
184 AddToAppletList(list_head, name, type)
185 RootRegion *list_head;
191 if (!list_head) return; /* ignore empty inserts */
193 nptr = (RegionEntry *)malloc(sizeof(RegionEntry));
196 twmrc_error_prefix();
197 fprintf (stderr, "unable to allocate %d bytes for RegionEntry\n",
198 sizeof(RegionEntry));
202 nptr->next = list_head->entries;
203 /* djhjr - 10/20/01 */
205 nptr->usedby = USEDBY_NAME;
206 nptr->u.name = (char*)strdup(name);
207 list_head->entries = nptr;