-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_window.c
667 lines (606 loc) · 23.2 KB
/
add_window.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
/****************************************************************************
* This module is based on Twm, but has been siginificantly modified
* by Rob Nation (nation@rocket.sanders.lockheed.com)
****************************************************************************/
/*****************************************************************************/
/** Copyright 1988 by Evans & Sutherland Computer Corporation, **/
/** Salt Lake City, Utah **/
/** Portions Copyright 1989 by the Massachusetts Institute of Technology **/
/** Cambridge, Massachusetts **/
/** **/
/** All Rights Reserved **/
/** **/
/** Permission to use, copy, modify, and distribute this software and **/
/** its documentation for any purpose and without fee is hereby **/
/** granted, provided that the above copyright notice appear in all **/
/** copies and that both that copyright notice and this permis- **/
/** sion notice appear in supporting documentation, and that the **/
/** names of Evans & Sutherland and M.I.T. not be used in advertising **/
/** in publicity pertaining to distribution of the software without **/
/** specific, written prior permission. **/
/** **/
/** EVANS & SUTHERLAND AND M.I.T. DISCLAIM ALL WARRANTIES WITH REGARD **/
/** TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- **/
/** ABILITY AND FITNESS, IN NO EVENT SHALL EVANS & SUTHERLAND OR **/
/** M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAM- **/
/** AGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA **/
/** OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER **/
/** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE **/
/** OR PERFORMANCE OF THIS SOFTWARE. **/
/*****************************************************************************/
/**********************************************************************
*
* Add a new window, put the titlbar and other stuff around
* the window
*
**********************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "fvwm.h"
#include <X11/Xatom.h>
#include "misc.h"
#include "screen.h"
extern Bool PPosOverride;
char NoName[] = "Untitled"; /* name if no name is specified */
extern Window Pager_w;
extern Bool KeyboardGrabbed;
/***********************************************************************
*
* Procedure:
* AddWindow - add a new window to the fvwm list
*
* Returned Value:
* (FvwmWindow *) - pointer to the FvwmWindow structure
*
* Inputs:
* w - the window id of the window to add
* iconm - flag to tell if this is an icon manager window
*
***********************************************************************/
FvwmWindow *AddWindow(Window w)
{
FvwmWindow *tmp_win; /* new fvwm window structure */
unsigned long valuemask; /* mask for create windows */
XSetWindowAttributes attributes; /* attributes for create windows */
Atom actual_type;
int actual_format;
unsigned long nitems, bytesafter;
int gravx, gravy; /* gravity signs for positioning */
int DragWidth;
int DragHeight,xl,yt;
char *value;
/* allocate space for the fvwm window */
tmp_win = (FvwmWindow *)calloc(1, sizeof(FvwmWindow));
if (tmp_win == (FvwmWindow *)0)
{
return NULL;
}
tmp_win->flags = 0;
tmp_win->w = w;
/*
* Make sure the client window still exists. We don't want to leave an
* orphan frame window if it doesn't. Since we now have the server
* grabbed, the window can't disappear later without having been
* reparented, so we'll get a DestroyNotify for it. We won't have
* gotten one for anything up to here, however.
*/
if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY,
&JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0)
{
free((char *)tmp_win);
return(NULL);
}
XSelectInput(dpy, tmp_win->w, PropertyChangeMask);
XGetWindowAttributes(dpy, tmp_win->w, &tmp_win->attr);
XFetchName(dpy, tmp_win->w, &tmp_win->name);
if(tmp_win->name == NULL)
tmp_win->name = NoName;
tmp_win->class = NoClass;
XGetClassHint(dpy, tmp_win->w, &tmp_win->class);
if (tmp_win->class.res_name == NULL)
tmp_win->class.res_name = NoName;
if (tmp_win->class.res_class == NULL)
tmp_win->class.res_class = NoName;
FetchWmProtocols (tmp_win);
tmp_win->wmhints = XGetWMHints(dpy, tmp_win->w);
/*
* The July 27, 1988 draft of the ICCCM ignores the size and position
* fields in the WM_NORMAL_HINTS property.
*/
if(XGetTransientForHint(dpy, tmp_win->w, &tmp_win->transientfor))
tmp_win->flags |= TRANSIENT;
else
tmp_win->flags &= ~TRANSIENT;
tmp_win->old_bw = tmp_win->attr.border_width;
/* if the window is in the NoTitle list, or is a transient,
* dont decorate it.
* If its a transient, and DecorateTransients was specified,
* decorate anyway
*/
if ((LookInList(Scr.NoTitle,tmp_win->name, &tmp_win->class, &value))||
((!Scr.DecorateTransients) && (tmp_win->flags & TRANSIENT)))
{
/* don't decorate */
tmp_win->frame_bw = Scr.NoBorderWidth;
tmp_win->title_height = tmp_win->title_width =
tmp_win->corner_width = tmp_win->boundary_width = 0;
}
else
{
/* go ahead and decorate */
tmp_win->frame_bw = Scr.BorderWidth;
tmp_win->title_height = Scr.TitleHeight + tmp_win->frame_bw;
tmp_win->boundary_width = Scr.BoundaryWidth;
tmp_win->corner_width = tmp_win->title_height + tmp_win->boundary_width;
tmp_win->flags |= BORDER;
}
if (LookInList(Scr.Sticky,tmp_win->name, &tmp_win->class, &value))
tmp_win->flags |= STICKY;
if (LookInList(Scr.Icons,tmp_win->name, &tmp_win->class, &value))
tmp_win->icon_bitmap_file = value;
if (LookInList(Scr.OnTop,tmp_win->name, &tmp_win->class,&value))
tmp_win->flags |= ONTOP;
GetWindowSizeHints (tmp_win);
GetGravityOffsets (tmp_win, &gravx, &gravy);
/*
* If
* o the window is a transient, or
*
* o a USPosition was requested
*
* then put the window where requested.
*
* If RandomPlacement was specified,
* then place the window in a psuedo-random location
*/
if (!(tmp_win->flags & TRANSIENT) && !(tmp_win->hints.flags & USPosition)
&&!PPosOverride)
{
/* Get user's window placement, unless RandomPlacement is specified */
if(Scr.RandomPlacement)
{
/* plase window in a random location */
if ((Scr.randomx += Scr.TitleHeight) > Scr.MyDisplayWidth / 2)
Scr.randomx = Scr.TitleHeight;
if ((Scr.randomy += 2 * Scr.TitleHeight) > Scr.MyDisplayHeight / 2)
Scr.randomy = 2 * Scr.TitleHeight;
tmp_win->attr.x = Scr.randomx;
tmp_win->attr.y = Scr.randomy;
}
else
{
/* wait for a button press to place the window */
while(XGrabPointer(dpy, Scr.Root, True, ButtonPressMask |
ButtonReleaseMask|ButtonMotionMask |
PointerMotionMask, GrabModeAsync, GrabModeAsync,
Scr.Root, Scr.PositionCursor,
CurrentTime) != GrabSuccess);
if(!KeyboardGrabbed)
while(XGrabKeyboard(dpy, Scr.Root, True, GrabModeAsync,
GrabModeAsync, CurrentTime)!=GrabSuccess);
XGrabServer(dpy);
/*
* Make sure the client window still exists. We don't want to leave an
* orphan frame window if it doesn't. Since we now have the server
* grabbed, the window can't disappear later without having been
* reparented, so we'll get a DestroyNotify for it. We won't have
* gotten one for anything up to here, however.
*/
if(XGetGeometry(dpy, w, &JunkRoot, &JunkX, &JunkY,
(unsigned int *)&DragWidth, (unsigned int *)&DragHeight,
&JunkBW, &JunkDepth) == 0)
{
free((char *)tmp_win);
XUngrabPointer(dpy,CurrentTime);
if(!KeyboardGrabbed)
XUngrabKeyboard(dpy,CurrentTime);
XUngrabServer(dpy);
return(NULL);
}
DragWidth += 2*tmp_win->boundary_width;
DragHeight += tmp_win->title_height + 2*tmp_win->boundary_width;
moveLoop(tmp_win,0,0,DragWidth,DragHeight, &xl, &yt);
tmp_win->attr.y = yt;
tmp_win->attr.x = xl;
XUngrabPointer(dpy,CurrentTime);
if(!KeyboardGrabbed)
XUngrabKeyboard(dpy,CurrentTime);
}
}
else
{
/* the USPosition was specified, or the window is a transient,
* so place it automatically */
/*
* Make sure the client window still exists. We don't want to leave an
* orphan frame window if it doesn't. Since we now have the server
* grabbed, the window can't disappear later without having been
* reparented, so we'll get a DestroyNotify for it. We won't have
* gotten one for anything up to here, however.
*/
XGrabServer(dpy);
if(XGetGeometry(dpy, w, &JunkRoot, &JunkX, &JunkY,
(unsigned int *)&DragWidth, (unsigned int *)&DragHeight,
&JunkBW, &JunkDepth) == 0)
{
free((char *)tmp_win);
XUngrabServer(dpy);
return(NULL);
}
/* put it where asked, mod title bar */
/* if the gravity is towards the top, move it by the title height */
tmp_win->attr.y -= gravy*tmp_win->frame_bw;
tmp_win->attr.x -= gravx*tmp_win->frame_bw;
if(gravy > 0)
tmp_win->attr.y -= 2*tmp_win->boundary_width + tmp_win->title_height;
if(gravx > 0)
tmp_win->attr.x -= 2*tmp_win->boundary_width;
}
XSetWindowBorderWidth (dpy, tmp_win->w, tmp_win->frame_bw);
XGetWindowProperty (dpy, tmp_win->w, XA_WM_ICON_NAME, 0L, 200L, False,
XA_STRING, &actual_type, &actual_format, &nitems,
&bytesafter,(unsigned char **)&tmp_win->icon_name);
if(tmp_win->icon_name==(char *)NULL)
tmp_win->icon_name = tmp_win->name;
tmp_win->flags &= ~ICON;
/* add the window into the fvwm list */
tmp_win->next = Scr.FvwmRoot.next;
if (Scr.FvwmRoot.next != NULL)
Scr.FvwmRoot.next->prev = tmp_win;
tmp_win->prev = &Scr.FvwmRoot;
Scr.FvwmRoot.next = tmp_win;
/* create windows */
tmp_win->frame_x = tmp_win->attr.x + tmp_win->old_bw - tmp_win->frame_bw;
tmp_win->frame_y = tmp_win->attr.y + tmp_win->old_bw - tmp_win->frame_bw;
tmp_win->frame_width = tmp_win->attr.width+2*tmp_win->boundary_width;
tmp_win->frame_height = tmp_win->attr.height + tmp_win->title_height+
2*tmp_win->boundary_width;
if (tmp_win->title_height)
{
valuemask = CWBackPixmap | CWBorderPixel | CWCursor | CWEventMask;
attributes.background_pixmap = None;
attributes.border_pixel = Scr.StdColors.fore;
attributes.cursor = Scr.FrameCursor;
attributes.event_mask = (SubstructureRedirectMask |
ButtonPressMask | ButtonReleaseMask |
EnterWindowMask | ExposureMask |
LeaveWindowMask);
tmp_win->frame =
XCreateWindow (dpy, Scr.Root, tmp_win->frame_x,tmp_win->frame_y,
tmp_win->frame_width, tmp_win->frame_height,
tmp_win->frame_bw,Scr.d_depth, CopyFromParent,
Scr.d_visual, valuemask, &attributes);
tmp_win->lead_w = tmp_win->frame;
XSetWindowBackground(dpy,tmp_win->frame,Scr.StdColors.back);
valuemask = (CWEventMask | CWBorderPixel | CWBackPixel |
CWCursor);
attributes.event_mask = (ButtonPressMask|ButtonReleaseMask|ExposureMask);
attributes.border_pixel = Scr.StdColors.fore;
attributes.background_pixel = Scr.StdColors.back;
attributes.cursor = Scr.SideBarCursor;
tmp_win->title_x = tmp_win->boundary_width +tmp_win->title_height+1;
tmp_win->title_y = tmp_win->boundary_width;
tmp_win->title_width = tmp_win->frame_width - 2*tmp_win->boundary_width
- 2*tmp_win->title_height-2;
if(tmp_win->title_width < 1)
tmp_win->title_width = 1;
tmp_win->top_w =
XCreateWindow (dpy, tmp_win->frame,tmp_win->corner_width, 0,
(tmp_win->frame_width - 2*tmp_win->corner_width),
tmp_win->boundary_width, 0, Scr.d_depth,
CopyFromParent, Scr.d_visual, valuemask, &attributes);
attributes.cursor = Scr.TitleCursor;
tmp_win->title_w =
XCreateWindow (dpy, tmp_win->frame, tmp_win->title_x, tmp_win->title_y,
tmp_win->title_width, tmp_win->title_height,0,
Scr.d_depth, CopyFromParent, Scr.d_visual, valuemask,
&attributes);
attributes.cursor = Scr.SysCursor;
tmp_win->sys_w =
XCreateWindow (dpy, tmp_win->frame, 0, 0, tmp_win->title_height,
tmp_win->title_height, 0, Scr.d_depth, CopyFromParent,
Scr.d_visual, valuemask, &attributes);
attributes.cursor = Scr.SysCursor;
tmp_win->iconify_w =
XCreateWindow (dpy, tmp_win->frame,
(tmp_win->title_width - tmp_win->title_height), 0,
tmp_win->title_height,tmp_win->title_height,0,
Scr.d_depth, CopyFromParent,Scr.d_visual, valuemask,
&attributes);
attributes.cursor = Scr.SideBarCursor;
tmp_win->right_side_w =
XCreateWindow (dpy, tmp_win->frame,
tmp_win->frame_width - tmp_win->boundary_width,
tmp_win->corner_width, tmp_win->boundary_width,
tmp_win->frame_height - 2*tmp_win->corner_width,
0, Scr.d_depth, CopyFromParent,
Scr.d_visual, valuemask, &attributes);
attributes.cursor = Scr.SideBarCursor;
tmp_win->left_side_w =
XCreateWindow (dpy, tmp_win->frame, 0, tmp_win->corner_width,
tmp_win->boundary_width-tmp_win->frame_bw,
tmp_win->frame_height - 2*tmp_win->corner_width,
0, Scr.d_depth, CopyFromParent,
Scr.d_visual, valuemask, &attributes);
attributes.cursor = Scr.SideBarCursor;
tmp_win->bottom_w =
XCreateWindow (dpy, tmp_win->frame, tmp_win->corner_width,
tmp_win->frame_height - tmp_win->boundary_width,
(tmp_win->frame_width - 2*tmp_win->corner_width),
tmp_win->boundary_width, 0, Scr.d_depth,
CopyFromParent,Scr.d_visual, valuemask, &attributes);
}
else
{
tmp_win->title_w = 0;
tmp_win->lead_w = tmp_win->w;
}
SetBorder (tmp_win, False,True,False);
valuemask = (CWEventMask | CWDontPropagate);
attributes.event_mask = (StructureNotifyMask | PropertyChangeMask |
ColormapChangeMask | VisibilityChangeMask |
EnterWindowMask | LeaveWindowMask);
if(tmp_win->w == Pager_w)
{
attributes.event_mask |=ButtonReleaseMask|ExposureMask;
attributes.do_not_propagate_mask = ButtonPressMask;
}
else
attributes.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
XChangeWindowAttributes (dpy, tmp_win->w, valuemask, &attributes);
XMapSubwindows (dpy, tmp_win->lead_w);
if(tmp_win->w != Pager_w)
XAddToSaveSet(dpy, tmp_win->w);
XReparentWindow(dpy, tmp_win->w, tmp_win->frame, tmp_win->boundary_width,
tmp_win->boundary_width+tmp_win->title_height);
/*
* Reparenting generates an UnmapNotify event, followed by a MapNotify.
* Set the map state to FALSE to prevent a transition back to
* WithdrawnState in HandleUnmapNotify. Map state gets set correctly
* again in HandleMapNotify.
*/
tmp_win->flags &= ~MAPPED;
SetupFrame (tmp_win, tmp_win->frame_x, tmp_win->frame_y,
tmp_win->frame_width, tmp_win->frame_height, True);
/* wait until the window is iconified and the icon window is mapped
* before creating the icon window
*/
tmp_win->icon_w = (int)NULL;
GrabButtons(tmp_win);
GrabKeys(tmp_win);
XSaveContext(dpy, tmp_win->w, FvwmContext, (caddr_t) tmp_win);
if (tmp_win->title_w)
{
XSaveContext(dpy, tmp_win->frame, FvwmContext, (caddr_t) tmp_win);
XSaveContext(dpy, tmp_win->title_w, FvwmContext, (caddr_t) tmp_win);
XSaveContext(dpy, tmp_win->left_side_w, FvwmContext, (caddr_t) tmp_win);
XSaveContext(dpy, tmp_win->right_side_w, FvwmContext, (caddr_t) tmp_win);
XSaveContext(dpy, tmp_win->bottom_w, FvwmContext, (caddr_t) tmp_win);
XSaveContext(dpy, tmp_win->top_w, FvwmContext, (caddr_t) tmp_win);
XSaveContext(dpy, tmp_win->sys_w, FvwmContext, (caddr_t) tmp_win);
XSaveContext(dpy, tmp_win->iconify_w, FvwmContext, (caddr_t) tmp_win);
}
if(Scr.ClickToFocus)
SetBorder (tmp_win, True,False,False);
InstallWindowColormaps(EnterNotify, tmp_win);
Scr.LastWindowRaised = tmp_win;
XRaiseWindow(dpy,tmp_win->lead_w);
KeepOnTop();
XUngrabServer(dpy);
RedrawPager();
return (tmp_win);
}
/***********************************************************************
*
* Procedure:
* GrabButtons - grab needed buttons for the window
*
* Inputs:
* tmp_win - the fvwm window structure to use
*
***********************************************************************/
void GrabButtons(FvwmWindow *tmp_win)
{
MouseButton *MouseEntry;
MouseEntry = Scr.MouseButtonRoot;
while(MouseEntry != (MouseButton *)0)
{
if((MouseEntry->func != (int)0)&&(MouseEntry->Context & C_WINDOW))
XGrabButton(dpy, MouseEntry->Button, MouseEntry->Modifier,
tmp_win->w,
True, ButtonPressMask | ButtonReleaseMask,
GrabModeAsync, GrabModeAsync, None,
Scr.FrameCursor);
MouseEntry = MouseEntry->NextButton;
}
return;
}
/***********************************************************************
*
* Procedure:
* GrabKeys - grab needed keys for the window
*
* Inputs:
* tmp_win - the fvwm window structure to use
*
***********************************************************************/
void GrabKeys(tmp_win)
FvwmWindow *tmp_win;
{
FuncKey *tmp;
for (tmp = Scr.FuncKeyRoot.next; tmp != NULL; tmp = tmp->next)
{
if(tmp->cont & C_WINDOW)
XGrabKey(dpy, tmp->keycode, tmp->mods, tmp_win->w, True,
GrabModeAsync, GrabModeAsync);
if ((tmp->cont & C_ICON)&&(tmp_win->icon_w))
XGrabKey(dpy, tmp->keycode, tmp->mods, tmp_win->icon_w, True,
GrabModeAsync, GrabModeAsync);
if((tmp->cont & C_TITLE)&&(tmp_win->title_w))
XGrabKey(dpy, tmp->keycode, tmp->mods, tmp_win->title_w, True,
GrabModeAsync, GrabModeAsync);
if((tmp->cont & C_SYS)&&(tmp_win->sys_w))
XGrabKey(dpy, tmp->keycode, tmp->mods, tmp_win->sys_w, True,
GrabModeAsync, GrabModeAsync);
if((tmp->cont & C_ICONIFY)&&(tmp_win->iconify_w))
XGrabKey(dpy, tmp->keycode, tmp->mods, tmp_win->iconify_w, True,
GrabModeAsync, GrabModeAsync);
if((tmp->cont & C_SIDEBAR)&&(tmp_win->left_side_w))
{
XGrabKey(dpy, tmp->keycode, tmp->mods, tmp_win->left_side_w, True,
GrabModeAsync, GrabModeAsync);
XGrabKey(dpy, tmp->keycode, tmp->mods, tmp_win->right_side_w, True,
GrabModeAsync, GrabModeAsync);
XGrabKey(dpy, tmp->keycode, tmp->mods, tmp_win->bottom_w, True,
GrabModeAsync, GrabModeAsync);
XGrabKey(dpy, tmp->keycode, tmp->mods, tmp_win->top_w, True,
GrabModeAsync, GrabModeAsync);
}
}
return;
}
/***********************************************************************
*
* Procedure:
* FetchWMProtocols - finds out which protocols the window supports
*
* Inputs:
* tmp - the fvwm window structure to use
*
***********************************************************************/
void FetchWmProtocols (FvwmWindow *tmp)
{
unsigned long flags = 0L;
Atom *protocols = NULL, *ap;
int i, n;
if (XGetWMProtocols (dpy, tmp->w, &protocols, &n))
{
for (i = 0, ap = protocols; i < n; i++, ap++)
{
if (*ap == _XA_WM_TAKE_FOCUS) flags |= DoesWmTakeFocus;
if (*ap == _XA_WM_SAVE_YOURSELF) flags |= DoesWmSaveYourself;
if (*ap == _XA_WM_DELETE_WINDOW) flags |= DoesWmDeleteWindow;
}
if (protocols) XFree ((char *) protocols);
}
tmp->protocols = flags;
return;
}
/***********************************************************************
*
* Procedure:
* GetWindowSizeHints - gets application supplied size info
*
* Inputs:
* tmp - the fvwm window structure to use
*
***********************************************************************/
void GetWindowSizeHints(FvwmWindow *tmp)
{
long supplied = 0;
static int gravs[] = { SouthEastGravity, SouthWestGravity,
NorthEastGravity, NorthWestGravity };
int right,bottom;
if (!XGetWMNormalHints (dpy, tmp->w, &tmp->hints, &supplied))
tmp->hints.flags = 0;
if (tmp->hints.flags & PResizeInc)
{
if (tmp->hints.width_inc == 0) tmp->hints.width_inc = 1;
if (tmp->hints.height_inc == 0) tmp->hints.height_inc = 1;
}
if (!(supplied & PWinGravity) &&
((tmp->hints.flags & USPosition)||
((tmp->hints.flags & PPosition)&&(PPosOverride))))
{
right = tmp->attr.x + tmp->attr.width + 2 * tmp->old_bw;
bottom = tmp->attr.y + tmp->attr.height + 2 * tmp->old_bw;
tmp->hints.win_gravity =
gravs[((Scr.MyDisplayHeight - bottom < (tmp->title_height+tmp->boundary_width)) ? 0 : 2) |
((Scr.MyDisplayWidth - right < tmp->boundary_width) ? 0 : 1)];
tmp->hints.flags |= PWinGravity;
}
}
/***********************************************************************
*
* Procedure:
* LookInList - look through a list for a window name, or class
*
* Returned Value:
* the ptr field of the list structure or NULL if the name
* or class was not found in the list
*
* Inputs:
* list - a pointer to the head of a list
* name - a pointer to the name to look for
* class - a pointer to the class to look for
*
***********************************************************************/
int LookInList(name_list *list, char *name, XClassHint *class, char **value)
{
name_list *nptr;
/* look for the name first */
for (nptr = list; nptr != NULL; nptr = nptr->next)
if (strcmp(name, nptr->name) == 0)
{
*value = nptr->value;
return True;
}
if (class)
{
/* look for the res_name next */
for (nptr = list; nptr != NULL; nptr = nptr->next)
if (strcmp(class->res_name, nptr->name) == 0)
{
*value = nptr->value;
return True;
}
/* finally look for the res_class */
for (nptr = list; nptr != NULL; nptr = nptr->next)
if (strcmp(class->res_class, nptr->name) == 0)
{
*value = nptr->value;
return True;
}
}
*value = (char *)0;
return False;
}
/************************************************************************
*
* Procedure:
* GetGravityOffsets - map gravity to (x,y) offset signs for adding
* to x and y when window is mapped to get proper placement.
*
************************************************************************/
struct _gravity_offset
{
int x, y;
};
void GetGravityOffsets (FvwmWindow *tmp, int *xp, int *yp)
{
static struct _gravity_offset gravity_offsets[11] =
{
{ 0, 0 }, /* ForgetGravity */
{ -1, -1 }, /* NorthWestGravity */
{ 0, -1 }, /* NorthGravity */
{ 1, -1 }, /* NorthEastGravity */
{ -1, 0 }, /* WestGravity */
{ 0, 0 }, /* CenterGravity */
{ 1, 0 }, /* EastGravity */
{ -1, 1 }, /* SouthWestGravity */
{ 0, 1 }, /* SouthGravity */
{ 1, 1 }, /* SouthEastGravity */
{ 0, 0 }, /* StaticGravity */
};
register int g = ((tmp->hints.flags & PWinGravity)
? tmp->hints.win_gravity : NorthWestGravity);
if (g < ForgetGravity || g > StaticGravity)
*xp = *yp = 0;
else
{
*xp = gravity_offsets[g].x;
*yp = gravity_offsets[g].y;
}
return;
}