~ctwm/ctwm/trunk

304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
1
/*
554.1.6 by Matthew Fuller
Collapse away redundant license texts in most .h files. These are all
2
 * Copyright 1992 Claude Lecommandeur.
20 by Claude Lecommandeur
CTWM version 3.6
3
 */
4
5
395.1.1 by Matthew Fuller
Move ctwm.h to always be included first.
6
#include "ctwm.h"
7
20 by Claude Lecommandeur
CTWM version 3.6
8
#include <stdio.h>
491.1.14 by Matthew Fuller
Remove incorrect pre-ANSI potential override prototypes for malloc()
9
#include <stdlib.h>
492.2.17 by Matthew Fuller
Cleanup some unneeded X headers and canoncalize ordering. In
10
20 by Claude Lecommandeur
CTWM version 3.6
11
#include <X11/Xatom.h>
340.1.1 by Matthew Fuller
Rearrange includes to be in what we'll call the Proper Order.
12
20 by Claude Lecommandeur
CTWM version 3.6
13
#include "screen.h"
93 by Richard Levitte
- Convert all functions to use proper prototypes.
14
#include "add_window.h"
524.1.5 by Matthew Fuller
Pull list.h out of screen.h and #include it in the places that need
15
#include "list.h"
20 by Claude Lecommandeur
CTWM version 3.6
16
#include "windowbox.h"
538.1.3 by Matthew Fuller
Rename the decorations*.h to win_decorations*.h.
17
#include "win_decorations.h"
538.1.5 by Matthew Fuller
And rename over resize.h.
18
#include "win_resize.h"
523.1.16 by Matthew Fuller
Move visible() into win_utils.
19
#include "win_utils.h"
614.1.23 by Maxime Soulé
Some geometries can be relative to a monitor
20
#include "xparsegeometry.h"
20 by Claude Lecommandeur
CTWM version 3.6
21
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
22
name_list **addWindowBox(char *boxname, char *geometry)
20 by Claude Lecommandeur
CTWM version 3.6
23
{
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
24
	WindowBox *winbox;
20 by Claude Lecommandeur
CTWM version 3.6
25
93 by Richard Levitte
- Convert all functions to use proper prototypes.
26
#if 0
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
27
	printf("addWindowBox : name = %s, geometry = %s\n", boxname, geometry);
93 by Richard Levitte
- Convert all functions to use proper prototypes.
28
#endif
491.1.8 by Matthew Fuller
Stop casting return values of [mc]alloc(). void * has existed for 27
29
	winbox = malloc(sizeof(WindowBox));
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
30
	winbox->next     = NULL;
31
	winbox->name     = strdup(boxname);
32
	winbox->geometry = strdup(geometry);
33
	winbox->winlist  = NULL;
34
	if(!Scr->FirstWindowBox) {
35
		Scr->FirstWindowBox = winbox;
36
	}
37
	return (&(winbox->winlist));
38
}
39
40
void createWindowBoxes(void)
41
{
42
	WindowBox *winbox;
43
	char title [128];
44
	XWMHints      wmhints;
45
	XSizeHints    sizehints;
46
47
	for(winbox = Scr->FirstWindowBox; winbox; winbox = winbox->next) {
48
		int mask, x, y, gravity;
49
		unsigned int w, h;
50
		Window win;
51
614.1.23 by Maxime Soulé
Some geometries can be relative to a monitor
52
		mask = RLayoutXParseGeometry(Scr->Layout, winbox->geometry,
53
		                             &x, &y, &w, &h);
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
54
		if(mask & XNegative) {
55
			x += Scr->rootw  - w;
56
			gravity = (mask & YNegative) ? SouthEastGravity : NorthEastGravity;
57
		}
58
		else {
59
			gravity = (mask & YNegative) ? SouthWestGravity : NorthWestGravity;
60
		}
61
		if(mask & YNegative) {
62
			y += Scr->rooth - h;
63
		}
64
65
		win = XCreateSimpleWindow(dpy, Scr->Root, x, y, w, h, 0, Scr->Black,
66
		                          Scr->White);
318 by Matthew Fuller
Turn a couple commented-out debug printf's into #if 0'd ones for
67
#if 0
68
		printf("createWindowBoxes : name = %s, win = 0x%x, x = %d, y = %d, w = %d, h = %d\n",
69
		       winbox->name, win, x, y, w, h);
70
#endif
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
71
		sprintf(title, "%s", winbox->name);
505.1.5 by Matthew Fuller
Convert other XSetStandardProperties()/XSetWM*() sequences into
72
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
73
		sizehints.flags  = USPosition | USSize | PWinGravity;
74
		sizehints.x      = x;
75
		sizehints.y      = y;
76
		sizehints.width  = w;
77
		sizehints.height = h;
78
		sizehints.win_gravity = gravity;
79
80
		wmhints.initial_state = NormalState;
81
		wmhints.input         = True;
82
		wmhints.flags         = InputHint | StateHint;
505.1.5 by Matthew Fuller
Convert other XSetStandardProperties()/XSetWM*() sequences into
83
84
		XmbSetWMProperties(dpy, win, title, title, NULL, 0,
505.1.6 by Matthew Fuller
make indent
85
		                   &sizehints, &wmhints, NULL);
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
86
87
		winbox->window = win;
497.1.16 by Matthew Fuller
Now that we've eliminated the magic about it, we can just turn this
88
		winbox->twmwin = AddWindow(win, AWT_WINDOWBOX, NULL, Scr->currentvs);
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
89
		if(!winbox->twmwin) {
90
			fprintf(stderr, "cannot create %s window box, exiting...\n", winbox->name);
91
			exit(1);
92
		}
492.2.75 by Matthew Fuller
Convert a bunch of boolean flags in the TwmWindow structure
93
		winbox->twmwin->iswinbox = true;
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
94
		XMapWindow(dpy, win);
95
	}
96
}
97
98
WindowBox *findWindowBox(TwmWindow *twmwin)
99
{
100
	WindowBox *winbox;
101
	if(twmwin->iswinbox) {
492.2.79 by Matthew Fuller
Replace various returns of 0 cast to a pointer type with NULL. Plus a
102
		return NULL;
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
103
	}
104
	if(!Scr->FirstWindowBox) {
492.2.79 by Matthew Fuller
Replace various returns of 0 cast to a pointer type with NULL. Plus a
105
		return NULL;
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
106
	}
107
	for(winbox = Scr->FirstWindowBox; winbox; winbox = winbox->next) {
563.1.4 by Matthew Fuller
Mechanically translate all these full_name references to name.
108
		if(LookInList(winbox->winlist, twmwin->name, &twmwin->class)) {
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
109
			if(visible(winbox->twmwin)) {
110
				twmwin->winbox = winbox;
492.2.79 by Matthew Fuller
Replace various returns of 0 cast to a pointer type with NULL. Plus a
111
				return winbox;
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
112
			}
113
		}
114
	}
492.2.79 by Matthew Fuller
Replace various returns of 0 cast to a pointer type with NULL. Plus a
115
	return NULL;
304.1.2 by Matthew Fuller
Run 'make indent' to reindent the world.
116
}
117
118
void ConstrainedToWinBox(TwmWindow *twmwin, int x, int y, int *nx, int *ny)
119
{
120
	XWindowAttributes attr;
121
122
	*nx = x;
123
	*ny = y;
124
	XGetWindowAttributes(dpy, twmwin->winbox->window, &attr);
125
	if(x < 0) {
126
		*nx = 0;
127
	}
128
	if(y < 0) {
129
		*ny = 0;
130
	}
131
	if(x >  attr.width - 1) {
132
		*nx = attr.width - 1;
133
	}
134
	if(y > attr.height - 1) {
135
		*ny = attr.height - 1;
136
	}
137
}
138
139
void fittocontent(TwmWindow *twmwin)
140
{
141
	TwmWindow   *t;
142
	int minx, miny, maxx, maxy, x, y, w, h;
143
	minx = Scr->rootw;
144
	miny = Scr->rooth;
145
	maxx = 0;
146
	maxy = 0;
147
	for(t = Scr->FirstWindow; t != NULL; t = t->next) {
148
		if(t->winbox && (t->winbox->twmwin == twmwin)) {
149
			if(t->frame_x < minx) {
150
				minx = t->frame_x;
151
			}
152
			if(t->frame_y < miny) {
153
				miny = t->frame_y;
154
			}
155
			w = t->frame_width  + 2 * t->frame_bw;
156
			h = t->frame_height + 2 * t->frame_bw;
157
			if(t->frame_x + w > maxx) {
158
				maxx = t->frame_x + w;
159
			}
160
			if(t->frame_y + h > maxy) {
161
				maxy = t->frame_y + h;
162
			}
163
		}
164
	}
165
	x = twmwin->frame_x + minx;
166
	y = twmwin->frame_y + miny;
167
	w = maxx - minx + 2 * twmwin->frame_bw3D;
168
	h = maxy - miny + 2 * twmwin->frame_bw3D;
169
	SetupWindow(twmwin, x, y, w, h, -1);
170
	for(t = Scr->FirstWindow; t != NULL; t = t->next) {
171
		if(t->winbox && (t->winbox->twmwin == twmwin)) {
172
			SetupWindow(t, t->frame_x - minx, t->frame_y - miny,
173
			            t->frame_width, t->frame_height, -1);
174
		}
175
	}
20 by Claude Lecommandeur
CTWM version 3.6
176
}