File: core.c

package info (click to toggle)
wmii2 2.5.2-11
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 608 kB
  • ctags: 925
  • sloc: ansic: 9,195; makefile: 184; sh: 11
file content (735 lines) | stat: -rw-r--r-- 17,697 bytes parent folder | download | duplicates (3)
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
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
/*
 * (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */

#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <X11/Xatom.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>

#include "wmiiwm.h"

static void     new_page(void *obj, char *cmd);
static void     _select_page(void *obj, char *cmd);
static void     _find_frame(void *obj, char *cmd);
static void     _destroy_page(void *obj, char *cmd);
static void     quit(void *obj, char *cmd);
static void     _attach_client(void *obj, char *cmd);
static void     _detach_client(void *obj, char *cmd);
static void     toggle_max_client(void *obj, char *cmd);
static void     _close_client(void *obj, char *cmd);
static void     pager(void *obj, char *cmd);
static void     icons(void *obj, char *cmd);

/* action table for /ctl namespace */
Action          core_acttbl[] = {
	{"new", new_page},
	{"destroy", _destroy_page},
	{"select", _select_page},
	{"find", _find_frame},
	{"attach", _attach_client},
	{"detach", _detach_client},
	{"togglemax", toggle_max_client},
	{"close", _close_client},
	{"quit", quit},
	{"pager", pager},
	{"icons", icons},
	{0, 0}
};

int 
comp_obj(void *c1, void *c2)
{
	return c1 == c2;
}

void 
run_action(File * f, void *obj, Action * acttbl)
{
	int             i;
	size_t          len;

	if (!f->content)
		return;
	for (i = 0; acttbl[i].name; i++) {
		len = strlen(acttbl[i].name);
		if (!strncmp(acttbl[i].name, (char *) f->content, len)) {
			if (f->size > len)
				acttbl[i].func(obj, &((char *) f->content)[len + 1]);
			else
				acttbl[i].func(obj, 0);
			return;
			break;
		}
	}
	fprintf(stderr, "wmiiwm: unknown action '%s'\n"
		"     or invalid ctl device\n", (char *) f->content);
}

static void 
quit(void *obj, char *cmd)
{
	ixps->runlevel = SHUTDOWN;
}

void 
invoke_core_event(File * f)
{
	if (!f->content)
		return;
	spawn(dpy, f->content);
}

void 
focus_page(Page * p, int raise, int down)
{
	if (!pages)
		return;
	if (p != pages[sel_page]) {
		hide_page(pages[sel_page]);
		prev_page = sel_page;
		sel_page = index_item((void **) pages, p);
		show_page(pages[sel_page]);
		core_files[CORE_PAGE_SELECTED]->content =
			p->files[P_PREFIX]->content;
		invoke_core_event(core_files[CORE_EVENT_PAGE_UPDATE]);
	}
	if (down) {
		if (is_managed_mode(p)) {
			if (p->managed_stack)
				focus_frame(p->managed_stack[0], raise, 0, down);
			else if (p->floating_stack)
				focus_frame(p->floating_stack[0], raise, 0, down);
			else {
				XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
				invoke_core_event(core_files[CORE_EVENT_CLIENT_UPDATE]);
			}
		} else {
			if (p->floating_stack)
				focus_frame(p->floating_stack[0], raise, 0, down);
			else if (p->managed_stack)
				focus_frame(p->managed_stack[0], raise, 0, down);
			else {
				XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
				invoke_core_event(core_files[CORE_EVENT_CLIENT_UPDATE]);
			}
		}
	}
}

static Frame   *
find_attached_frame_by_name(char *name)
{
	size_t          len;
	int             i;
	if (!name || name[0] == '\0')
		return 0;
	len = strlen(name);

	for (i = 0; frames && frames[i]; i++) {
		if (!strncmp(frames[i]->files[F_NAME]->content, name, len))
			return frames[i];
	}
	return 0;
}

static void 
_find_frame(void *obj, char *cmd)
{
	Frame          *f;
	if (!pages || !cmd)
		return;
	f = find_attached_frame_by_name(cmd);
	if (!f)
		return;
	focus_page(f->page, 0, 0);
	focus_frame(f, 1, 0, 1);
}

static void
scale_rect(XRectangle * from_dim, XRectangle * to_dim,
	   XRectangle * src, XRectangle * tgt)
{
	double          wfact = (double) to_dim->width / (double) from_dim->width;
	double          hfact = (double) to_dim->height / (double) from_dim->height;

	tgt->x = to_dim->x + (src->x * wfact);
	tgt->y = to_dim->y + (src->y * hfact);
	tgt->width = (src->width * wfact);
	tgt->height = (src->height * hfact);

	if (tgt->width < 1)
		tgt->width = 1;
	if (tgt->height < 1)
		tgt->height = 1;
}

static void 
draw_pager_page(Page * p, Draw * d)
{
	int             i;
	XRectangle      r = d->rect;
	XFontStruct    *font = blitz_getfont(dpy,
			     core_files[CORE_PAGER_SEL_TEXT_FONT]->content);
	if (p == pages[sel_page]) {
		d->bg = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_SEL_BG_COLOR]->content);
		d->fg = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_SEL_TEXT_COLOR]->content);
		d->border = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_SEL_BORDER_COLOR]->content);
		d->font = font;
	} else {
		d->bg = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_NORM_BG_COLOR]->content);
		d->fg = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_NORM_TEXT_COLOR]->content);
		d->border = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_NORM_BORDER_COLOR]->content);
		d->font = font;
	}
	d->data = p->files[P_NAME]->content;
	blitz_drawlabel(dpy, d);
	XSync(dpy, False);

	for (i = count_items((void **) p->managed_stack) - 1;
	     (i > -1) && p->managed_stack && p->managed_stack[i]; i--) {
		if (!i) {
			d->bg = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_SEL_CLIENT_COLOR]->content);
			d->fg = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_SEL_CTEXT_COLOR]->content);
			d->border = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_SEL_CBORDER_COLOR]->content);
			d->font = font;
		} else {
			d->bg = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_NORM_CLIENT_COLOR]->content);
			d->fg = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_NORM_CTEXT_COLOR]->content);
			d->border = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_NORM_CBORDER_COLOR]->content);
			d->font = font;
		}
		d->data =
			p->managed_stack[i]->clients[p->managed_stack[i]->sel]->
			files[C_NAME]->content;
		scale_rect(&rect, &r, &p->managed_stack[i]->managed_rect,
			   &d->rect);
		blitz_drawlabel(dpy, d);
		XSync(dpy, False);
	}

	for (i = count_items((void **) p->floating_stack) - 1;
	     (i > -1) && p->floating_stack && p->floating_stack[i]; i--) {
		if (!i) {
			d->bg = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_SEL_CLIENT_COLOR]->content);
			d->fg = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_SEL_CTEXT_COLOR]->content);
			d->border = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_SEL_CBORDER_COLOR]->content);
			d->font = font;
		} else {
			d->bg = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_NORM_CLIENT_COLOR]->content);
			d->fg = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_NORM_CTEXT_COLOR]->content);
			d->border = blitz_loadcolor(dpy, screen_num, core_files[CORE_PAGER_NORM_CBORDER_COLOR]->content);
			d->font = font;
		}
		d->data =
			p->floating_stack[i]->clients[p->floating_stack[i]->sel]->
			files[C_NAME]->content;
		scale_rect(&rect, &r, &p->floating_stack[i]->floating_rect,
			   &d->rect);
		blitz_drawlabel(dpy, d);
		XSync(dpy, False);
	}
	XFreeFont(dpy, font);
}

static void 
draw_pager()
{
	unsigned int    ic, ir, tw, th, rows, cols, size;
	int             i = 0;
	int             dx;
	Draw            d = {0};

	blitz_getbasegeometry((void **) pages, &size, &cols, &rows);
	dx = (cols - 1) * GAP;	/* GAPpx space */
	tw = (rect.width - dx) / cols;
	th = ((double) tw / rect.width) * rect.height;
	d.drawable = transient;
	d.gc = transient_gc;
	for (ir = 0; ir < rows; ir++) {
		for (ic = 0; ic < cols; ic++) {
			d.rect.x = ic * tw + (ic * GAP);
			d.rect.width = tw;
			if (rows == 1)
				d.rect.y = 0;
			else
				d.rect.y = ir * (rect.height - th) / (rows - 1);
			d.rect.height = th;
			if (!pages[i])
				return;
			draw_pager_page(pages[i], &d);
			i++;
		}
	}
}

static Page    *
xy_to_pager_page(int x, int y)
{
	unsigned int    ic, ir, tw, th, rows, cols, size;
	int             i = 0;
	int             dx;
	XRectangle      r;

	if (!pages)
		return 0;
	blitz_getbasegeometry((void **) pages, &size, &cols, &rows);
	dx = (cols - 1) * GAP;	/* GAPpx space */
	tw = (rect.width - dx) / cols;
	th = ((double) tw / rect.width) * rect.height;

	for (ir = 0; ir < rows; ir++) {
		for (ic = 0; ic < cols; ic++) {
			r.x = ic * tw + (ic * GAP);
			r.width = tw;
			if (rows == 1)
				r.y = 0;
			else
				r.y = ir * (rect.height - th) / (rows - 1);
			r.height = th;
			if (!pages[i])
				return 0;
			if (blitz_ispointinrect(x, y, &r))
				return pages[i];
			i++;
		}
	}
	return 0;
}

static int 
handle_kpress(XKeyEvent * e)
{
	KeySym          ksym = XKeycodeToKeysym(dpy, e->keycode, 0);

	if (ksym >= XK_1 && ksym <= XK_9)
		return ksym - XK_1;
	else if (ksym == XK_0)
		return 9;
	else if (ksym >= XK_a && ksym <= XK_z)
		return 10 + ksym - XK_a;

	return -1;
}

static void 
pager(void *obj, char *cmd)
{
	XEvent          ev;
	int             i;

	if (!pages)
		return;

	XClearWindow(dpy, transient);
	XMapRaised(dpy, transient);
	draw_pager();
	while (XGrabKeyboard(dpy, transient, True, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess)
		usleep(1000);

	for (;;) {
		while (!XCheckWindowEvent(dpy, transient, ButtonPressMask | KeyPressMask, &ev)) {
			usleep(20000);
			continue;
		}

		switch (ev.type) {
		case KeyPress:
			XUnmapWindow(dpy, transient);
			if ((i = handle_kpress(&ev.xkey)) != -1)
				if (i < count_items((void **) pages))
					focus_page(pages[i], 0, 1);
			XUngrabKeyboard(dpy, CurrentTime);
			return;
			break;
		case ButtonPress:
			XUnmapWindow(dpy, transient);
			if (ev.xbutton.button == Button1) {
				Page           *p = xy_to_pager_page(ev.xbutton.x, ev.xbutton.y);
				if (p)
					focus_page(p, 0, 1);
			}
			return;
			break;
		}
	}
}

static void 
draw_icons()
{
	unsigned int    i, ic, ir, tw, th, rows, cols, size;
	int             dx, dy;

	if (!detached)
		return;
	blitz_getbasegeometry((void **) detached, &size, &cols, &rows);
	dx = (cols - 1) * GAP;	/* GAPpx space */
	dy = (rows - 1) * GAP;	/* GAPpx space */
	tw = (rect.width - dx) / cols;
	th = (rect.height - dy) / rows;

	XClearWindow(dpy, transient);
	XMapRaised(dpy, transient);
	i = 0;
	for (ir = 0; ir < rows; ir++) {
		for (ic = 0; ic < cols; ic++) {
			Client         *c = detached[i++];
			XRectangle      cr;
			if (!c)
				return;
			cr.x = ic * tw + (ic * GAP);
			cr.y = ir * th + (ir * GAP);
			cr.width = tw;
			cr.height = th;
			XMoveResizeWindow(dpy, c->win, cr.x, cr.y, cr.width,
					  cr.height);
			configure_client(c);
			show_client(c);
			XRaiseWindow(dpy, c->win);
			grab_client(c, AnyModifier, AnyButton);
			XSync(dpy, False);
		}
	}
}


static void 
icons(void *obj, char *cmd)
{
	XEvent          ev;
	int             i, n;
	Client         *c;

	if (!detached)
		return;

	XClearWindow(dpy, transient);
	XMapRaised(dpy, transient);
	draw_icons();
	while (XGrabKeyboard(dpy, transient, True, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess)
		usleep(1000);

	for (;;) {
		while (!XCheckMaskEvent(dpy, ButtonPressMask | KeyPressMask, &ev)) {
			usleep(20000);
			continue;
		}
		switch (ev.type) {
		case KeyPress:
			XUnmapWindow(dpy, transient);
			if ((n = handle_kpress(&ev.xkey)) != -1) {
				for (i = 0; detached && detached[i]; i++)
					hide_client(detached[i]);
				if (n - 1 < i) {
					c = detached[n];
					detached = (Client **) detach_item((void **) detached, c,
							  sizeof(Client *));
					attach_client(c);
				}
			} else {
				for (i = 0; detached && detached[i]; i++)
					hide_client(detached[i]);
			}
			XUngrabKeyboard(dpy, CurrentTime);
			return;
			break;
		case ButtonPress:
			if (ev.xbutton.button == Button1) {
				XUnmapWindow(dpy, transient);
				for (i = 0; detached && detached[i]; i++)
					hide_client(detached[i]);
				if ((c = win_to_client(ev.xbutton.window))) {
					detached =
						(Client **) detach_item((void **) detached, c,
							  sizeof(Client *));
					attach_client(c);
				}
				XUngrabKeyboard(dpy, CurrentTime);
			}
			return;
			break;
		}
	}
}

static int 
find_page_by_name(char *name)
{
	int             i;
	size_t          len;
	if (!name || name[0] == '\0')
		return 0;
	len = strlen(name);

	for (i = 0; pages && pages[i]; i++) {
		if (!strncmp(pages[i]->files[P_NAME]->content, name, len))
			return i;
	}
	return -1;
}

static void 
_close_client(void *obj, char *cmd)
{
	Client *target = sel;
	sel = 0;
	if (target && target->frame && pages && target->frame->page == pages[sel_page])
		close_client(target);
}

static void 
_attach_client(void *obj, char *cmd)
{
	if (detached) {
		Client         *c = detached[0];
		detached =
			(Client **) detach_item((void **) detached, c,
						sizeof(Client *));
		attach_client(c);
	}
}

static void 
toggle_max_client(void *obj, char *cmd)
{
	Frame          *f;
	if (!pages)
		return;
	f = get_selected(pages[sel_page]);
	if (!f)
		return;
	if (f->before_max) {
		int             i;
		for (i = 0; pages[i] && (pages[i] != f->before_max); i++);
		if (!pages[i])
			return;
		detach_frame_from_page(f, 0);
		focus_page(f->before_max, 0, 1);
		attach_frame_to_page(f->before_max, f, !f->floating);
		f->before_max = 0;
	} else {
		Page           *p;
		f->before_max = f->page;
		detach_frame_from_page(f, 0);
		hide_page(pages[sel_page]);
		p = alloc_page("1");
		if (p->layout)
			p->layout->deinit(p);
		p->files[P_MANAGED_LAYOUT]->content = strdup("max");
		p->layout = get_layout(p->files[P_MANAGED_LAYOUT]->content);
		if (p->layout) {
			p->layout->init(p);
			p->layout->arrange(p);
			p->files[P_MODE]->content = p->files[P_MANAGED_PREFIX]->content;
			core_files[CORE_PAGE_SELECTED]->content = p->files[P_PREFIX]->content;
			invoke_core_event(core_files[CORE_EVENT_PAGE_UPDATE]);
			attach_frame_to_page(p, f, 1);
		} else {
			core_files[CORE_PAGE_SELECTED]->content = p->files[P_PREFIX]->content;
			invoke_core_event(core_files[CORE_EVENT_PAGE_UPDATE]);
			f->floating_rect = rect;
			attach_frame_to_page(p, f, 0);
		}
	}
	resize_frame(f, rect_of_frame(f), 0, 1);
	draw_frame(f);
}

static void 
_detach_client(void *obj, char *cmd)
{
	Frame          *f;
	if (!pages)
		return;
	f = get_selected(pages[sel_page]);
	if (!f)
		return;
	detach_client_from_frame(f->clients[f->sel], 0, 0, 0);
}

static void 
_select_page(void *obj, char *cmd)
{
	int             idx;
	if (!pages || !cmd)
		return;
	if (!strncmp(cmd, "prev", 5))
		idx = index_prev_item((void **) pages, pages[sel_page]);
	else if (!strncmp(cmd, "next", 5))
		idx = index_next_item((void **) pages, pages[sel_page]);
	else
		idx = find_page_by_name(cmd);
	if (idx >= 0)
		focus_page(pages[idx], 0, 1);
}

void 
destroy_page(Page * p)
{
	int             i, size;

	if (p->layout)
		p->layout->deinit(p);
	while (p->managed) {
		size = count_items((void **) p->managed[0]->clients);
		for (i = 0; i < size; i++)
			detach_client_from_frame(p->managed[0]->clients[0], 0, 0, 1);
	}
	while (p->floating) {
		size = count_items((void **) p->floating[0]->clients);
		for (i = 0; i < size; i++)
			detach_client_from_frame(p->floating[0]->clients[0], 0, 0, 1);
	}
	free_page(p);
	if (pages) {
		p = pages[sel_page];
		show_page(p);
		core_files[CORE_PAGE_SELECTED]->content =
			p->files[P_PREFIX]->content;
		focus_page(p, 0, 1);
	}
	invoke_core_event(core_files[CORE_EVENT_PAGE_UPDATE]);
}

static void 
_destroy_page(void *obj, char *cmd)
{
	if (!pages)
		return;
	destroy_page(pages[sel_page]);
}

static void 
new_page(void *obj, char *cmd)
{
	if (pages)
		hide_page(pages[sel_page]);
	alloc_page("0");
}

Client         *
win_to_client(Window w)
{
	int             i;

	for (i = 0; clients && clients[i]; i++)
		if (clients[i]->win == w)
			return clients[i];
	return 0;
}

Frame          *
win_to_frame(Window w)
{
	int             i;

	for (i = 0; frames && frames[i]; i++)
		if (frames[i]->win == w)
			return frames[i];
	return 0;
}

void 
scan_wins()
{
	int             i;
	unsigned int    num;
	Window         *wins;
	XWindowAttributes wa;
	Window          d1, d2;
	Client         *c;

	if (XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
		for (i = 0; i < num; i++) {
			if (!XGetWindowAttributes(dpy, wins[i], &wa))
				continue;
			if (wa.override_redirect
			    || XGetTransientForHint(dpy, wins[i], &d1))
				continue;
			if (wa.map_state == IsViewable) {
				c = alloc_client(wins[i]);
				_init_client(c, &wa);
				attach_client(c);
			}
		}
	}
	if (wins)
		XFree(wins);
}

void           *
get_func(void *acttbl[][2], int rows, char *fname)
{
	int             i;
	for (i = 0; i < rows; i++) {
		if (!strncmp((char *) acttbl[i][0], fname, MAX_BUF)) {
			return acttbl[i][1];
		}
	}
	return 0;
}

int 
win_proto(Window w)
{
	Atom           *protocols;
	long            res;
	int             protos = 0;
	int             i;

	res = property(dpy, w, wm_protocols, XA_ATOM,
		       20L, ((unsigned char **) &protocols));
	if (res <= 0) {
		return protos;
	}
	for (i = 0; i < res; i++) {
		if (protocols[i] == wm_delete) {
			protos |= PROTO_DEL;
		}
	}
	free((char *) protocols);
	return protos;
}

int 
win_state(Window w)
{
	/* state hints */
	XWMHints       *hints = XGetWMHints(dpy, w);
	int             res;

	long           *prop = 0;
	if (property(dpy, w, wm_state, wm_state,
		     2L, ((unsigned char **) &prop)) > 0) {
		res = (int) *prop;
		free((long *) prop);
	} else {
		res = hints ? hints->initial_state : NormalState;
	}

	if (hints) {
		free(hints);
	}
	return res;
}

void 
handle_after_write(IXPServer * s, File * f)
{
	if (f == core_files[CORE_CTL])
		run_action(f, 0, core_acttbl);
	else if (f == core_files[CORE_TRANS_COLOR]) {
		unsigned long   col[1];
		col[0] = xorcolor.pixel;
		XFreeColors(dpy, DefaultColormap(dpy, screen_num), col, 1, 0);
		XAllocNamedColor(dpy, DefaultColormap(dpy, screen_num),
				 core_files[CORE_TRANS_COLOR]->content,
				 &xorcolor, &xorcolor);
		XSetForeground(dpy, xorgc, xorcolor.pixel);
	}
	check_event(0);
}