1 /*
2  *  Window Maker window manager
3  *
4  *  Copyright (c) 1997-2003 Alfredo K. Kojima
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License along
17  *  with this program; if not, write to the Free Software Foundation, Inc.,
18  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 #include "wconfig.h"
21 
22 #include <X11/Xlib.h>
23 #include <X11/Xutil.h>
24 #include <X11/Xatom.h>
25 #ifdef USE_XSHAPE
26 #include <X11/extensions/shape.h>
27 #endif
28 
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 
33 #include "WindowMaker.h"
34 #include "framewin.h"
35 #include "window.h"
36 #include "properties.h"
37 #include "actions.h"
38 #include "icon.h"
39 #include "client.h"
40 #include "colormap.h"
41 #include "stacking.h"
42 #include "appicon.h"
43 #include "appmenu.h"
44 #include "wmspec.h"
45 #include "misc.h"
46 
47 
48 /*
49  *--------------------------------------------------------------------
50  * wClientRestore--
51  * 	Reparent the window back to the root window.
52  *
53  *--------------------------------------------------------------------
54  */
wClientRestore(WWindow * wwin)55 void wClientRestore(WWindow * wwin)
56 {
57 #if 0
58 	int gx, gy;
59 
60 	wClientGetGravityOffsets(wwin, &gx, &gy);
61 	/* set the position of the frame on screen */
62 	wwin->frame_x -= gx * wwin->screen_ptr->frame_border_width;
63 	wwin->frame_y -= gy * wwin->screen_ptr->frame_border_width;
64 	/* if gravity is to the south, account for the border sizes */
65 	if (gy > 0)
66 		wwin->frame_y += (wwin->frame->top_width + wwin->frame->bottom_width);
67 #endif
68 	XSetWindowBorderWidth(dpy, wwin->client_win, wwin->old_border_width);
69 	XReparentWindow(dpy, wwin->client_win, wwin->screen_ptr->root_win, wwin->frame_x, wwin->frame_y);
70 
71 	/* don't let the window get iconified after restart */
72 	/*
73 	   if (wwin->flags.shaded)
74 	   wClientSetState(wwin, NormalState, None);
75 	 */
76 }
77 
78 /*
79  *----------------------------------------------------------------------
80  * wClientSetState--
81  * 	Set the state of the client window to one of the window
82  * states defined in ICCCM (Iconic, Withdrawn, Normal)
83  *
84  * Side effects:
85  * 	The WM_STATE property of the window is updated as well as the
86  * WWindow.state variable.
87  *----------------------------------------------------------------------
88  */
wClientSetState(WWindow * wwin,int state,Window icon_win)89 void wClientSetState(WWindow * wwin, int state, Window icon_win)
90 {
91 	long data[2];
92 
93 	wwin->state = state;
94 
95 	data[0] = (unsigned long)state;
96 	data[1] = (unsigned long)icon_win;
97 
98 	XChangeProperty(dpy, wwin->client_win, w_global.atom.wm.state,
99 			w_global.atom.wm.state, 32, PropModeReplace,
100 			(unsigned char *)data, 2);
101 }
102 
wClientGetGravityOffsets(WWindow * wwin,int * ofs_x,int * ofs_y)103 void wClientGetGravityOffsets(WWindow * wwin, int *ofs_x, int *ofs_y)
104 {
105 	switch (wwin->normal_hints->win_gravity) {
106 	case ForgetGravity:
107 	case CenterGravity:
108 	case StaticGravity:
109 		*ofs_x = 0;
110 		*ofs_y = 0;
111 		break;
112 	case NorthWestGravity:
113 		*ofs_x = -1;
114 		*ofs_y = -1;
115 		break;
116 	case NorthGravity:
117 		*ofs_x = 0;
118 		*ofs_y = -1;
119 		break;
120 	case NorthEastGravity:
121 		*ofs_x = 1;
122 		*ofs_y = -1;
123 		break;
124 	case WestGravity:
125 		*ofs_x = -1;
126 		*ofs_y = 0;
127 		break;
128 	case EastGravity:
129 		*ofs_x = 1;
130 		*ofs_y = 0;
131 		break;
132 	case SouthWestGravity:
133 		*ofs_x = -1;
134 		*ofs_y = 1;
135 		break;
136 	case SouthGravity:
137 		*ofs_x = 0;
138 		*ofs_y = 1;
139 		break;
140 	case SouthEastGravity:
141 		*ofs_x = 1;
142 		*ofs_y = 1;
143 		break;
144 	}
145 }
146 
wClientConfigure(WWindow * wwin,XConfigureRequestEvent * xcre)147 void wClientConfigure(WWindow * wwin, XConfigureRequestEvent * xcre)
148 {
149 	XWindowChanges xwc;
150 	int nx, ny, nwidth, nheight;
151 	int ofs_x, ofs_y;
152 
153 	/*  printf("configure event: %d %d %d %d\n", xcre->x, xcre->y, xcre->width, xcre->height); */
154 
155 	if (wwin == NULL) {
156 		/*
157 		 * configure a window that was not mapped by us
158 		 */
159 		xwc.x = xcre->x;
160 		xwc.y = xcre->y;
161 		xwc.width = xcre->width;
162 		xwc.height = xcre->height;
163 		xwc.border_width = xcre->border_width;
164 		xwc.stack_mode = xcre->detail;
165 		xwc.sibling = xcre->above;
166 		XConfigureWindow(dpy, xcre->window, xcre->value_mask, &xwc);
167 		return;
168 	}
169 #ifdef USE_XSHAPE
170 	if (w_global.xext.shape.supported) {
171 		int junk;
172 		unsigned int ujunk;
173 		int b_shaped;
174 
175 		XShapeSelectInput(dpy, wwin->client_win, ShapeNotifyMask);
176 		XShapeQueryExtents(dpy, wwin->client_win, &b_shaped, &junk, &junk,
177 				   &ujunk, &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
178 		wwin->flags.shaped = b_shaped;
179 	}
180 #endif
181 	if (xcre->value_mask & CWStackMode) {
182 		WObjDescriptor *desc;
183 		WWindow *sibling;
184 
185 		if ((xcre->value_mask & CWSibling) &&
186 		    (XFindContext(dpy, xcre->above, w_global.context.client_win, (XPointer *) & desc) == XCSUCCESS)
187 		    && (desc->parent_type == WCLASS_WINDOW)) {
188 			sibling = desc->parent;
189 			xwc.sibling = sibling->frame->core->window;
190 		} else {
191 			xwc.sibling = xcre->above;
192 		}
193 		xwc.stack_mode = xcre->detail;
194 		XConfigureWindow(dpy, wwin->frame->core->window,
195 				 xcre->value_mask & (CWSibling | CWStackMode), &xwc);
196 		/* fix stacking order */
197 		RemakeStackList(wwin->screen_ptr);
198 	}
199 
200 	wClientGetGravityOffsets(wwin, &ofs_x, &ofs_y);
201 
202 	if (xcre->value_mask & CWBorderWidth) {
203 		wwin->old_border_width = xcre->border_width;
204 	}
205 
206 	if (!wwin->flags.shaded) {
207 		/* If the window is shaded, wrong height will be set for the window */
208 		if (xcre->value_mask & CWX) {
209 			nx = xcre->x;
210 			/* Subtracting the border makes the window shift by 1 pixel -Dan */
211 			/*if (HAS_BORDER(wwin)) {
212 			   nx -= wwin->screen_ptr->frame_border_width;
213 			   } */
214 		} else {
215 			nx = wwin->frame_x;
216 		}
217 
218 		if (xcre->value_mask & CWY) {
219 			ny = xcre->y - ((ofs_y < 0) ? 0 : wwin->frame->top_width);
220 			/* Subtracting the border makes the window shift by 1 pixel -Dan */
221 			/*if (HAS_BORDER(wwin)) {
222 			   ny -= wwin->screen_ptr->frame_border_width;
223 			   } */
224 		} else {
225 			ny = wwin->frame_y;
226 		}
227 
228 		if (xcre->value_mask & CWWidth)
229 			nwidth = xcre->width;
230 		else
231 			nwidth = wwin->frame->core->width;
232 
233 		if (xcre->value_mask & CWHeight)
234 			nheight = xcre->height;
235 		else
236 			nheight = wwin->frame->core->height - wwin->frame->top_width - wwin->frame->bottom_width;
237 
238 		/* Don't overwrite the saved geometry unnecessarily. */
239 		if (!(xcre->value_mask & (CWX | CWY | CWWidth | CWHeight)))
240 			return;
241 
242 		if (nwidth != wwin->old_geometry.width)
243 			wwin->flags.maximized &= ~(MAX_HORIZONTAL | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS);
244 		if (nheight != wwin->old_geometry.height)
245 			wwin->flags.maximized &= ~(MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
246 
247 		wWindowConfigure(wwin, nx, ny, nwidth, nheight);
248 		wwin->old_geometry.x = nx;
249 		wwin->old_geometry.y = ny;
250 		wwin->old_geometry.width = nwidth;
251 		wwin->old_geometry.height = nheight;
252 	}
253 }
254 
wClientSendProtocol(WWindow * wwin,Atom protocol,Time time)255 void wClientSendProtocol(WWindow * wwin, Atom protocol, Time time)
256 {
257 	XEvent event;
258 
259 	event.xclient.type = ClientMessage;
260 	event.xclient.message_type = w_global.atom.wm.protocols;
261 	event.xclient.format = 32;
262 	event.xclient.display = dpy;
263 	event.xclient.window = wwin->client_win;
264 	event.xclient.data.l[0] = protocol;
265 	event.xclient.data.l[1] = time;
266 	event.xclient.data.l[2] = 0;
267 	event.xclient.data.l[3] = 0;
268 	XSendEvent(dpy, wwin->client_win, False, NoEventMask, &event);
269 	XSync(dpy, False);
270 }
271 
wClientKill(WWindow * wwin)272 void wClientKill(WWindow * wwin)
273 {
274 	XKillClient(dpy, wwin->client_win);
275 
276 	XFlush(dpy);
277 }
278 
279 /*
280  *----------------------------------------------------------------------
281  * wClientCheckProperty--
282  * 	Handles PropertyNotify'es, verifying which property was
283  * changed and updating internal state according to that, like redrawing
284  * the icon title when it is changed.
285  *
286  * Side effects:
287  * 	Depends on the changed property.
288  *
289  * TODO: _GNUSTEP_WM_ATTR
290  *----------------------------------------------------------------------
291  */
wClientCheckProperty(WWindow * wwin,XPropertyEvent * event)292 void wClientCheckProperty(WWindow * wwin, XPropertyEvent * event)
293 {
294 	XWindowAttributes attribs;
295 	XWMHints *new_hints;
296 	int i, g1, g2;
297 	char *tmp = NULL;
298 
299 	switch (event->atom) {
300 	case XA_WM_NAME:
301 		if (!wwin->flags.net_has_title) {
302 			/* window title was changed */
303 			if (!wFetchName(dpy, wwin->client_win, &tmp)) {
304 				wWindowUpdateName(wwin, NULL);
305 			} else {
306 				wWindowUpdateName(wwin, tmp);
307 			}
308 			if (tmp)
309 				XFree(tmp);
310 		}
311 		break;
312 
313 	case XA_WM_ICON_NAME:
314 		/* Title has changed, update the icon title */
315 		if (wwin->icon) {
316 			wIconChangeTitle(wwin->icon, wwin);
317 			wIconPaint(wwin->icon);
318 		}
319 		break;
320 
321 	case XA_WM_COMMAND:
322 		if (wwin->main_window != None) {
323 			WApplication *wapp = wApplicationOf(wwin->main_window);
324 			char *command;
325 
326 			if (!wapp || !wapp->app_icon || wapp->app_icon->docked)
327 				break;
328 
329 			command = GetCommandForWindow(wwin->main_window);
330 			if (command) {
331 				if (wapp->app_icon->command)
332 					wfree(wapp->app_icon->command);
333 				wapp->app_icon->command = command;
334 			}
335 		}
336 		break;
337 
338 	case XA_WM_HINTS:
339 		/* WM_HINTS */
340 
341 		new_hints = XGetWMHints(dpy, wwin->client_win);
342 
343 		/* group leader update
344 		 *
345 		 * This means that the window is setting the leader after
346 		 * it was mapped, changing leaders or removing the leader.
347 		 *
348 		 * Valid state transitions are:
349 		 *
350 		 *          _1            __2
351 		 *         / \           /  \
352 		 *         v |           v  |
353 		 *         (GC)         (GC')
354 		 *        /  ^          /   ^
355 		 *       3|  |4        5|   |6
356 		 *        |  |          |   |
357 		 *        v  /          v   /
358 		 *        (G'C)        (G'C')
359 		 *
360 		 * Where G is the window_group hint, C is CLIENT_LEADER property
361 		 * and ' indicates the hint is unset.
362 		 *
363 		 * 1,2 - change group leader to new value of window_group
364 		 * 3 - change leader to value of CLIENT_LEADER
365 		 * 4 - change leader to value of window_group
366 		 * 5 - destroy application
367 		 * 6 - create application
368 		 */
369 		if (new_hints && (new_hints->flags & WindowGroupHint)
370 		    && new_hints->window_group != None) {
371 			g2 = 1;
372 		} else {
373 			g2 = 0;
374 		}
375 		if (wwin->wm_hints && (wwin->wm_hints->flags & WindowGroupHint)
376 		    && wwin->wm_hints->window_group != None) {
377 			g1 = 1;
378 		} else {
379 			g1 = 0;
380 		}
381 
382 		if (wwin->client_leader) {
383 			if (g1 && g2 && wwin->wm_hints->window_group != new_hints->window_group) {
384 				i = 1;
385 			} else if (g1 && !g2) {
386 				i = 3;
387 			} else if (!g1 && g2) {
388 				i = 4;
389 			} else {
390 				i = 0;
391 			}
392 		} else {
393 			if (g1 && g2 && wwin->wm_hints->window_group != new_hints->window_group) {
394 				i = 2;
395 			} else if (g1 && !g2) {
396 				i = 5;
397 			} else if (!g1 && g2) {
398 				i = 6;
399 			} else {
400 				i = 0;
401 			}
402 		}
403 
404 		/* Handling this may require more work. -Dan */
405 		if (wwin->fake_group != NULL) {
406 			i = 7;
407 		}
408 
409 		if (wwin->wm_hints)
410 			XFree(wwin->wm_hints);
411 
412 		wwin->wm_hints = new_hints;
413 
414 		/* do action according to state transition */
415 		switch (i) {
416 			/* 3 - change leader to value of CLIENT_LEADER */
417 		case 3:
418 			wApplicationDestroy(wApplicationOf(wwin->main_window));
419 			wwin->main_window = wwin->client_leader;
420 			wwin->group_id = None;
421 			wApplicationCreate(wwin);
422 			break;
423 
424 			/* 1,2,4 - change leader to new value of window_group */
425 		case 1:
426 		case 2:
427 		case 4:
428 			wApplicationDestroy(wApplicationOf(wwin->main_window));
429 			wwin->main_window = new_hints->window_group;
430 			wwin->group_id = wwin->main_window;
431 			wApplicationCreate(wwin);
432 			break;
433 
434 			/* 5 - destroy application */
435 		case 5:
436 			wApplicationDestroy(wApplicationOf(wwin->main_window));
437 			wwin->main_window = None;
438 			wwin->group_id = None;
439 			break;
440 
441 			/* 6 - create application */
442 		case 6:
443 			wwin->main_window = new_hints->window_group;
444 			wwin->group_id = wwin->main_window;
445 			wApplicationCreate(wwin);
446 			break;
447 			/* 7 - we have a fake window group id, so just ignore anything else */
448 		case 7:
449 			break;
450 		}
451 
452 		if (wwin->wm_hints) {
453 			/* update icon */
454 			if ((wwin->wm_hints->flags & IconPixmapHint)
455 			    || (wwin->wm_hints->flags & IconWindowHint)) {
456 				WApplication *wapp;
457 
458 				if (wwin->flags.miniaturized && wwin->icon)
459 					wIconUpdate(wwin->icon);
460 
461 				wapp = wApplicationOf(wwin->main_window);
462 				if (wapp && wapp->app_icon) {
463 					wIconUpdate(wapp->app_icon->icon);
464 					wAppIconPaint(wapp->app_icon);
465 				}
466 			}
467 
468 			if (wwin->wm_hints->flags & UrgencyHint)
469 				wwin->flags.urgent = 1;
470 			else
471 				wwin->flags.urgent = 0;
472 			wAppBounceWhileUrgent(wApplicationOf(wwin->main_window));
473 		/*} else if (wwin->fake_group!=NULL) {
474 			wwin->group_id = wwin->fake_group->leader; */
475 		} else {
476 			wwin->group_id = None;
477 		}
478 		break;
479 
480 	case XA_WM_NORMAL_HINTS:
481 		/* normal (geometry) hints */
482 		{
483 			int foo;
484 			unsigned bar;
485 
486 			if (XGetWindowAttributes(dpy, wwin->client_win, &attribs) != 0)
487 				wClientGetNormalHints(wwin, &attribs, False, &foo, &foo, &bar, &bar);
488 			/* TODO: should we check for consistency of the current
489 			 * size against the new geometry hints? */
490 		}
491 		break;
492 
493 	case XA_WM_TRANSIENT_FOR:
494 		{
495 			Window new_owner;
496 			WWindow *owner;
497 
498 			if (!XGetTransientForHint(dpy, wwin->client_win, &new_owner)) {
499 				new_owner = None;
500 			} else {
501 				if (new_owner == 0 || new_owner == wwin->client_win) {
502 					new_owner = wwin->screen_ptr->root_win;
503 				}
504 			}
505 			if (new_owner != wwin->transient_for) {
506 				owner = wWindowFor(wwin->transient_for);
507 				if (owner) {
508 					if (owner->flags.semi_focused) {
509 						owner->flags.semi_focused = 0;
510 						if ((owner->flags.mapped || owner->flags.shaded)
511 						    && owner->frame)
512 							wFrameWindowPaint(owner->frame);
513 					}
514 				}
515 				owner = wWindowFor(new_owner);
516 				if (owner) {
517 					if (!owner->flags.semi_focused) {
518 						owner->flags.semi_focused = 1;
519 						if ((owner->flags.mapped || owner->flags.shaded)
520 						    && owner->frame)
521 							wFrameWindowPaint(owner->frame);
522 					}
523 				}
524 				wwin->transient_for = new_owner;
525 				if (new_owner == None) {
526 					if (WFLAGP(wwin, no_miniaturizable)) {
527 						wwin->client_flags.no_miniaturizable = 0;
528 						wwin->client_flags.no_miniaturize_button = 0;
529 						if (wwin->frame)
530 							wWindowConfigureBorders(wwin);
531 					}
532 				} else if (!WFLAGP(wwin, no_miniaturizable)) {
533 					wwin->client_flags.no_miniaturizable = 1;
534 					wwin->client_flags.no_miniaturize_button = 1;
535 					if (wwin->frame)
536 						wWindowConfigureBorders(wwin);
537 				}
538 			}
539 		}
540 		break;
541 
542 	default:
543 		if (event->atom == w_global.atom.wm.protocols) {
544 
545 			PropGetProtocols(wwin->client_win, &wwin->protocols);
546 
547 			wwin->client_flags.kill_close = !wwin->protocols.DELETE_WINDOW;
548 
549 			if (wwin->frame)
550 				wWindowUpdateButtonImages(wwin);
551 
552 		} else if (event->atom == w_global.atom.wm.colormap_windows) {
553 
554 			GetColormapWindows(wwin);
555 			wColormapInstallForWindow(wwin->screen_ptr, wwin);
556 
557 		} else if (event->atom == w_global.atom.wmaker.menu) {
558 			WApplication *wapp;
559 
560 			wapp = wApplicationOf(wwin->main_window);
561 			if (wapp) {
562 				if (wapp->menu) {
563 					/* update menu */
564 					/* TODO: remake appmenu update */
565 					wAppMenuDestroy(wapp->menu);
566 				}
567 				if (wwin->fake_group) {
568 					WScreen *scr = wwin->screen_ptr;
569 					WWindow *foo = scr->focused_window;
570 					WFakeGroupLeader *fPtr = wwin->fake_group;
571 
572 					wApplicationDestroy(wapp);
573 					while (foo) {
574 						if (foo->fake_group && foo->fake_group == fPtr) {
575 							foo->client_flags.shared_appicon = 0;
576 							foo->fake_group = NULL;
577 
578 							if (foo->group_id != None)
579 								foo->main_window = foo->group_id;
580 							else if (foo->client_leader != None)
581 								foo->main_window = foo->client_leader;
582 							else if (WFLAGP(foo, emulate_appicon))
583 								foo->main_window = foo->client_win;
584 							else
585 								foo->main_window = None;
586 
587 							if (foo->main_window)
588 								wApplicationCreate(foo);
589 						}
590 						foo = foo->prev;
591 					}
592 
593 					if (fPtr->leader != None)
594 						XDestroyWindow(dpy, fPtr->leader);
595 					fPtr->retainCount = 0;
596 					fPtr->leader = None;
597 					fPtr->origLeader = None;
598 
599 					wapp = wApplicationOf(wwin->main_window);
600 					if (wapp) {
601 						wapp->menu = wAppMenuGet(scr, wwin->main_window);
602 					}
603 					if (wPreferences.auto_arrange_icons) {
604 						wArrangeIcons(wwin->screen_ptr, True);
605 					}
606 				} else {
607 					wapp->menu = wAppMenuGet(wwin->screen_ptr, wwin->main_window);
608 				}
609 				/* make the appmenu be mapped */
610 				wSetFocusTo(wwin->screen_ptr, NULL);
611 				wSetFocusTo(wwin->screen_ptr, wwin->screen_ptr->focused_window);
612 			}
613 		} else if (event->atom == w_global.atom.gnustep.wm_attr) {
614 			GNUstepWMAttributes *attr;
615 
616 			PropGetGNUstepWMAttr(wwin->client_win, &attr);
617 
618 			wWindowUpdateGNUstepAttr(wwin, attr);
619 
620 			XFree(attr);
621 		} else {
622 			wNETWMCheckClientHintChange(wwin, event);
623 		}
624 	}
625 }
626 
627 /*
628  *----------------------------------------------------------------------
629  * wClientGetNormalHints--
630  * 	Get size (normal) hints and a default geometry for the client
631  * window. The hints are also checked for inconsistency. If geometry is
632  * True, the returned data will account for client specified initial
633  * geometry.
634  *
635  * Side effects:
636  * 	normal_hints is filled with valid data.
637  *----------------------------------------------------------------------
638  */
639 void
wClientGetNormalHints(WWindow * wwin,XWindowAttributes * wattribs,Bool geometry,int * x,int * y,unsigned * width,unsigned * height)640 wClientGetNormalHints(WWindow * wwin, XWindowAttributes * wattribs, Bool geometry,
641 		      int *x, int *y, unsigned *width, unsigned *height)
642 {
643 	int pre_icccm = 0;	/* not used */
644 
645 	/* find a position for the window */
646 	if (!wwin->normal_hints)
647 		wwin->normal_hints = XAllocSizeHints();
648 
649 	if (!PropGetNormalHints(wwin->client_win, wwin->normal_hints, &pre_icccm)) {
650 		wwin->normal_hints->flags = 0;
651 	}
652 	*x = wattribs->x;
653 	*y = wattribs->y;
654 
655 	*width = wattribs->width;
656 	*height = wattribs->height;
657 
658 	if (!(wwin->normal_hints->flags & PWinGravity)) {
659 		wwin->normal_hints->win_gravity = NorthWestGravity;
660 	}
661 	if (!(wwin->normal_hints->flags & PMinSize)) {
662 		wwin->normal_hints->min_width = MIN_WINDOW_SIZE;
663 		wwin->normal_hints->min_height = MIN_WINDOW_SIZE;
664 	}
665 	if (!(wwin->normal_hints->flags & PBaseSize)) {
666 		wwin->normal_hints->base_width = 0;
667 		wwin->normal_hints->base_height = 0;
668 	}
669 	if (!(wwin->normal_hints->flags & PMaxSize)) {
670 		wwin->normal_hints->max_width = wwin->screen_ptr->scr_width * 2;
671 		wwin->normal_hints->max_height = wwin->screen_ptr->scr_height * 2;
672 	}
673 
674 	/* some buggy apps set weird hints.. */
675 	if (wwin->normal_hints->min_width <= 0)
676 		wwin->normal_hints->min_width = MIN_WINDOW_SIZE;
677 
678 	if (wwin->normal_hints->min_height <= 0)
679 		wwin->normal_hints->min_height = MIN_WINDOW_SIZE;
680 
681 	if (wwin->normal_hints->max_width < wwin->normal_hints->min_width)
682 		wwin->normal_hints->max_width = wwin->normal_hints->min_width;
683 
684 	if (wwin->normal_hints->max_height < wwin->normal_hints->min_height)
685 		wwin->normal_hints->max_height = wwin->normal_hints->min_height;
686 
687 	if (!(wwin->normal_hints->flags & PResizeInc)) {
688 		wwin->normal_hints->width_inc = 1;
689 		wwin->normal_hints->height_inc = 1;
690 	} else {
691 		if (wwin->normal_hints->width_inc <= 0)
692 			wwin->normal_hints->width_inc = 1;
693 		if (wwin->normal_hints->height_inc <= 0)
694 			wwin->normal_hints->height_inc = 1;
695 	}
696 
697 	if (wwin->normal_hints->flags & PAspect) {
698 		if (wwin->normal_hints->min_aspect.x < 1)
699 			wwin->normal_hints->min_aspect.x = 1;
700 		if (wwin->normal_hints->min_aspect.y < 1)
701 			wwin->normal_hints->min_aspect.y = 1;
702 
703 		if (wwin->normal_hints->max_aspect.x < 1)
704 			wwin->normal_hints->max_aspect.x = 1;
705 		if (wwin->normal_hints->max_aspect.y < 1)
706 			wwin->normal_hints->max_aspect.y = 1;
707 	}
708 
709 	if (wwin->normal_hints->min_height > wwin->normal_hints->max_height) {
710 		wwin->normal_hints->min_height = wwin->normal_hints->max_height;
711 	}
712 	if (wwin->normal_hints->min_width > wwin->normal_hints->max_width) {
713 		wwin->normal_hints->min_width = wwin->normal_hints->max_width;
714 	}
715 #ifdef IGNORE_PPOSITION
716 	wwin->normal_hints->flags &= ~PPosition;
717 #endif
718 
719 	if (pre_icccm && !wwin->screen_ptr->flags.startup && geometry) {
720 		if (wwin->normal_hints->flags & (USPosition | PPosition)) {
721 			*x = wwin->normal_hints->x;
722 			*y = wwin->normal_hints->y;
723 		}
724 		if (wwin->normal_hints->flags & (USSize | PSize)) {
725 			*width = wwin->normal_hints->width;
726 			*height = wwin->normal_hints->height;
727 		}
728 	}
729 }
730 
GetColormapWindows(WWindow * wwin)731 void GetColormapWindows(WWindow * wwin)
732 {
733 #ifndef NO_CRASHES
734 	if (wwin->cmap_windows) {
735 		XFree(wwin->cmap_windows);
736 	}
737 
738 	wwin->cmap_windows = NULL;
739 	wwin->cmap_window_no = 0;
740 
741 	if (!XGetWMColormapWindows(dpy, wwin->client_win, &(wwin->cmap_windows), &(wwin->cmap_window_no))
742 	    || !wwin->cmap_windows) {
743 		wwin->cmap_window_no = 0;
744 		wwin->cmap_windows = NULL;
745 	}
746 #endif
747 }
748