aboutsummaryrefslogtreecommitdiff
path: root/src/libmemlayer/ltorear.c
blob: d53e8cc95e3a3c757c886690a9f47b2c007990d7 (plain)
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
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>
#include <memlayer.h>

void
_memltorear(Memimage *i, Memimage *rear)
{
	Memlayer *l;
	Memscreen *s;
	Memimage *f, *r, *rr;
	Rectangle x;
	int overlap;

	l = i->layer;
	s = l->screen;
	while(l->rear != rear){
		r = l->rear;
		x = l->screenr;
		overlap = rectclip(&x, r->layer->screenr);
		if(overlap){
			memlhide(i, x);
			l->clear = 0;
		}
		/* swap l and r in screen's list */
		rr = r->layer->rear;
		f = l->front;
		if(rr == nil)
			s->rearmost = i;
		else
			rr->layer->front = i;
		if(f == nil)
			s->frontmost = r;
		else
			f->layer->rear = r;
		l->rear = rr;
		l->front = r;
		r->layer->rear = i;
		r->layer->front = f;
		if(overlap)
			memlexpose(r, x);
	}
}

void
memltorear(Memimage *i)
{
	_memltorear(i, nil);
	_memlsetclear(i->layer->screen);
}

void
memltorearn(Memimage **ip, int n)
{
	Memimage *i, *rear;
	Memscreen *s;

	if(n == 0)
		return;
	rear = nil;
	while(--n >= 0){
		i = *ip++;
		_memltorear(i, rear);
		rear = i;
	}
	s = rear->layer->screen;
	_memlsetclear(s);
}