File: outline.c

package info (click to toggle)
afterstep 2.2.12-18.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,184 kB
  • sloc: ansic: 201,695; sh: 5,894; xml: 3,721; makefile: 2,094; perl: 1,558; cpp: 811
file content (397 lines) | stat: -rw-r--r-- 11,762 bytes parent folder | download | duplicates (6)
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
/****************************************************************************
 * Copyright (c) 1999,2001 Sasha Vasko <sasha at aftercode.net>
 * Copyright (c) 1998 Rafal Wierzbicki  (rubber bands) <rafal@mcss.mcmaster.ca>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Completely rewritten from outline.c copyrighted by :
 *      by Rob Nation
 *      by Bo Yang
 *      by Frank Fejes
 *      by Eric Tremblay
 ****************************************************************************/

#include "../configure.h"

#define LOCAL_DEBUG
#include "asapp.h"
#include "../libAfterImage/afterimage.h"
#include "afterstep.h"
#include "screen.h"
#include "decor.h"
#include "moveresize.h"

#define THICKNESS 3

int
make_rectangle_segments (ASOutlineSegment * s, int x, int y,
												 unsigned int width, unsigned int height)
{
	if (s) {
		/* Outline box : */
		s[1].x = s[0].x = x + 1;
		s[0].y = y;
		s[1].y = y + height - 1;
		s[1].size = s[0].size = width;
		s[1].vertical = s[0].vertical = False;

		s[2].x = x;
		s[3].x = x + width - 1;
		s[3].y = s[2].y = y + 1;
		s[3].size = s[2].size = height;
		s[3].vertical = s[2].vertical = True;
	}
	return 4;
}

int
make_lt_corner_segments (ASOutlineSegment * s, int x, int y,
												 unsigned int width, unsigned int height)
{
	if (s) {
		s[0].x = x + 1;
		s[0].y = y;
		s[0].size = width;
		s[0].vertical = False;

		s[1].x = x;
		s[1].y = y + 1;
		s[1].size = height;
		s[1].vertical = True;
	}
	return 2;
}

int
make_br_corner_segments (ASOutlineSegment * s, int x, int y,
												 unsigned int width, unsigned int height)
{
	if (s) {
		s[0].x = x - width - 1;
		s[0].y = y - THICKNESS;
		s[0].size = width;
		s[0].vertical = False;

		s[1].x = x - THICKNESS;
		s[1].y = y - height - 1;
		s[1].size = height;
		s[1].vertical = True;
	}
	return 2;
}

int
make_fvwm_segments (ASOutlineSegment * s, struct MRRectangle *geom,
										unsigned int scr_width, unsigned int scr_height)
{
	int count = 0;

	/* Outline box : */
	count +=
			make_rectangle_segments (s, geom->x, geom->y, geom->width,
															 geom->height);
	/* Inside grid : */
	count +=
			make_rectangle_segments (s ? &(s[count]) : NULL, geom->x + 1,
															 geom->y + geom->height / 3, geom->width - 2,
															 geom->height / 3);
	count +=
			make_rectangle_segments (s ? &(s[count]) : NULL,
															 geom->x + geom->width / 3, geom->y + 1,
															 geom->width / 3, geom->height - 2);
	return count;
}

int
make_box_segments (ASOutlineSegment * s, struct MRRectangle *geom,
									 unsigned int scr_width, unsigned int scr_height)
{
	return make_rectangle_segments (s, geom->x, geom->y, geom->width,
																	geom->height);
}

int
make_wmaker_segments (ASOutlineSegment * s, struct MRRectangle *geom,
											unsigned int scr_width, unsigned int scr_height)
{
	int count = 0;

	/* Outline box : */
	count +=
			make_rectangle_segments (s, geom->x, geom->y, geom->width,
															 geom->height);
	if (s) {
		s = &(s[count]);

		s[1].x = s[0].x = geom->x + 1;
		s[0].y = geom->y + CORNER_WIDTH;
		s[1].y = geom->y + geom->height - BOUNDARY_WIDTH - THICKNESS;
		s[1].size = s[0].size = geom->width - 2;
		s[1].vertical = s[0].vertical = False;
	}
	return count + 2;
}

int
make_tek_segments (ASOutlineSegment * s, struct MRRectangle *geom,
									 unsigned int scr_width, unsigned int scr_height)
{
	int count = 0;

	count +=
			make_rectangle_segments (s, geom->x, geom->y, geom->width,
															 geom->height);
	count +=
			make_lt_corner_segments (s ? &(s[count]) : NULL, geom->x - 6,
															 geom->y - 6, geom->width / 2,
															 geom->height / 2);
	count +=
			make_br_corner_segments (s ? &(s[count]) : NULL,
															 geom->x + geom->width + 6,
															 geom->y + geom->height + 6, geom->width / 2,
															 geom->height / 2);

	return count;
}

int
make_tek2_segments (ASOutlineSegment * s, struct MRRectangle *geom,
										unsigned int scr_width, unsigned int scr_height)
{
	int count = 0;

	count +=
			make_rectangle_segments (s, geom->x, geom->y, geom->width,
															 geom->height);
	count +=
			make_lt_corner_segments (s ? &(s[count]) : NULL, geom->x - 12,
															 geom->y - 12, geom->width / 3,
															 geom->height / 3);
	count +=
			make_lt_corner_segments (s ? &(s[count]) : NULL, geom->x - 6,
															 geom->y - 6, geom->width / 2,
															 geom->height / 2);
	count +=
			make_br_corner_segments (s ? &(s[count]) : NULL,
															 geom->x + geom->width + 6,
															 geom->y + geom->height + 6, geom->width / 2,
															 geom->height / 2);
	count +=
			make_br_corner_segments (s ? &(s[count]) : NULL,
															 geom->x + geom->width + 12,
															 geom->y + geom->height + 12,
															 geom->width / 3, geom->height / 3);
	return count;
}

int
make_corner_segments (ASOutlineSegment * s, struct MRRectangle *geom,
											unsigned int scr_width, unsigned int scr_height)
{
	int corner_height, corner_width;
	int count = 0;

	corner_height = geom->height / 8;
	corner_width = geom->width / 8;

	corner_width = FIT_IN_RANGE (5, corner_width, 32);
	corner_height = FIT_IN_RANGE (5, corner_height, 32);

	count +=
			make_lt_corner_segments (s ? &(s[count]) : NULL, geom->x, geom->y,
															 corner_width, corner_height);
	count +=
			make_br_corner_segments (s ? &(s[count]) : NULL,
															 geom->x + geom->width,
															 geom->y + geom->height, corner_width,
															 corner_height);

	/* crosshair */
	if (s) {
		s = &(s[count]);

		s[0].x = geom->x + geom->width / 2 - 5;
		s[0].y = geom->y + geom->height / 2 - 1;
		s[0].vertical = False;

		s[1].x = geom->x + geom->width / 2 - 1;
		s[1].y = geom->y + geom->height / 2 - 5;
		s[1].vertical = True;

		s[1].size = s[0].size = 11;
	}
	return count + 2;
}

int
make_hash_segments (ASOutlineSegment * s, struct MRRectangle *geom,
										unsigned int scr_width, unsigned int scr_height)
{
	int count = 0;

	count +=
			make_rectangle_segments (s, geom->x, geom->y, geom->width,
															 geom->height);
	if (s) {
		s = &(s[count]);
		s[1].x = s[0].x = 0;
		s[0].y = geom->y - 1;
		s[1].y = (geom->y + geom->height - THICKNESS) + 1;
		s[1].size = s[0].size = scr_width;
		s[1].vertical = s[0].vertical = False;

		s[2].x = geom->x - 1;
		s[3].x = (geom->x + geom->width - THICKNESS) + 1;
		s[3].y = s[2].y = 0;
		s[3].size = s[2].size = scr_height;
		s[3].vertical = s[2].vertical = True;
	}

	return count + 4;
}

int
make_twm_segments (ASOutlineSegment * s, struct MRRectangle *geom,
									 unsigned int scr_width, unsigned int scr_height)
{
	int count = 0;

	/* Outline box : */
	count +=
			make_rectangle_segments (s, geom->x, geom->y, geom->width,
															 geom->height);
	/* Inside grid : */
	if (s) {
		s = &(s[count]);
		s[0].y = geom->y + geom->height / 3;
		s[1].y = geom->y + geom->height - geom->height / 3;
		s[1].x = s[0].x = geom->x + 1;
		s[1].size = s[0].size = geom->width - 1;
		s[1].vertical = s[0].vertical = False;

		s[2].x = geom->x + geom->width / 3;
		s[3].x = geom->x + geom->width - geom->width / 3;
		s[3].y = s[2].y = geom->y + 1;
		s[3].size = s[2].size = geom->height - 1;
		s[3].vertical = s[2].vertical = True;
	}
	return count + 4;
}


as_outline_handler outline_handlers[MAX_RUBBER_BAND + 1] = {
	make_fvwm_segments,						/* 0 is the old default FVWM style look                                */
	make_box_segments,						/* 1 is a single rectangle the size of the window.                     */
	make_wmaker_segments,					/* 2 is a WindowMaker style outline, showing the titlebar and handles, if the window has them. */
	make_tek_segments,						/* 3 is a cool tech-looking outline.                                   */
	make_tek2_segments,						/* 4 is another cool tech-looking outline.                             */
	make_corner_segments,					/* 5 is the corners of the window with a crosshair in the middle.      */
	make_hash_segments,						/* 6 is lines spanning the whole screen framing the window. (CAD style) */
	make_twm_segments							/* 7 is the old twm style look.                                        */
};

/***********************************************************************
 *	MoveOutline - move a window outline
 ***********************************************************************/

ASOutlineSegment *make_outline_segments (ASWidget * parent, MyLook * look)
{
	ASOutlineSegment *s;
	XSetWindowAttributes attr;		/* attributes for create */
	int count = 0, i;
	ScreenInfo *scr;
	MRRectangle rdum = { 0, 0, 10, 10 };

	count =
			outline_handlers[look->RubberBand % (MAX_RUBBER_BAND + 1)] (NULL,
																																	&rdum, 0,
																																	0);

	LOCAL_DEBUG_OUT ("outline should have %d segments", count);
	if (count <= 0)
		return NULL;

	s = safecalloc (count + 1, sizeof (ASOutlineSegment));
	scr = AS_WIDGET_SCREEN (parent);
	attr.background_pixel = scr->asv->black_pixel;
	attr.border_pixel = scr->asv->white_pixel;
	attr.save_under = True;
	attr.event_mask = 0;					/*ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
																   PointerMotionMask | EnterWindowMask | LeaveWindowMask; */
	for (i = count - 1; i >= 0; --i) {
		s[i].w = create_screen_window (AS_WIDGET_SCREEN (parent), AS_WIDGET_WINDOW (parent), -20, -20, 10, 1, 1,	/* 1 pixel wide border */
																	 InputOutput,
																	 (CWBackPixel | CWBorderPixel |
																		CWSaveUnder | CWEventMask), &attr);
		XMapRaised (dpy, s[i].w);
		SHOW_CHECKPOINT;
	}
	return s;
}

void move_outline (ASMoveResizeData * data)
{

	if (data && data->outline) {
		unsigned int mask = CWStackMode;
		XWindowChanges xwc;
		register int i;
		int rband = data->look->RubberBand % (MAX_RUBBER_BAND + 1);
		ASOutlineSegment *s = data->outline;
		int count = outline_handlers[rband] (s, &(data->curr),
																				 AS_WIDGET_WIDTH (data->parent),
																				 AS_WIDGET_HEIGHT (data->parent));

		if (count <= 0)
			return;
		if ((xwc.sibling = data->below_sibling) != None) {
			mask |= CWSibling;
			xwc.stack_mode = Below;
		} else
			xwc.stack_mode = Above;
		XConfigureWindow (dpy, data->geometry_display->w, mask, &xwc);
		xwc.sibling = data->geometry_display->w;
		mask |= CWSibling | CWX | CWY | CWWidth | CWHeight;
		xwc.stack_mode = Below;
		for (i = 0; i < count; ++i) {
			xwc.x = s[i].x;
			xwc.y = s[i].y;
			xwc.width = s[i].vertical ? 1 : MAX (s[i].size - 2, 1);
			xwc.height = s[i].vertical ? MAX (s[i].size - 2, 1) : 1;
			XConfigureWindow (dpy, s[i].w, mask, &xwc);
			xwc.sibling = s[i].w;
		}
		/* hiding the rest of the frame : */
		while (s[i].w != None)
			XMoveResizeWindow (dpy, s[i++].w, -20, -20, -10, -10);
		XSync (dpy, False);
	}
}

void destroy_outline_segments (ASOutlineSegment ** psegments)
{
	if (psegments == NULL)
		return;
	if (*psegments) {
		register ASOutlineSegment *s = *psegments;
		register int i = 0;

		while (s[i].w != None)
			XDestroyWindow (dpy, s[i++].w);
		XSync (dpy, False);
		free (s);
		*psegments = NULL;
	}
}