summaryrefslogtreecommitdiff
path: root/patch/scratchpad_alt_1.c
blob: 6724d5c6dd74a3346d692278ae5030dbe6f78488 (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
70
71
72
static Client * scratchpad_last_showed = NULL;

void
scratchpad_hide()
{
	if (selmon->sel) {
		selmon->sel->tags = SCRATCHPAD_MASK;
		selmon->sel->isfloating = 1;
		focus(NULL);
		arrange(selmon);
	}
}

_Bool
scratchpad_last_showed_is_killed(void)
{
	Client *c;
	for (c = selmon->clients; c && c != scratchpad_last_showed; c = c->next);
	return (c == NULL);
}

void
scratchpad_remove()
{
	if (selmon->sel && scratchpad_last_showed != NULL && selmon->sel == scratchpad_last_showed)
		scratchpad_last_showed = NULL;
}

void
scratchpad_show()
{
	if (scratchpad_last_showed == NULL || scratchpad_last_showed_is_killed()) {
		scratchpad_show_first();
		return;
	}

	if (scratchpad_last_showed->tags != SCRATCHPAD_MASK) {
		scratchpad_last_showed->tags = SCRATCHPAD_MASK;
		focus(NULL);
		arrange(selmon);
		return;
	}

	Client *c;

	for (c = selmon->clients; c && c != scratchpad_last_showed; c = c->next);
	for (c = (c ? c->next : NULL); c && c->tags != SCRATCHPAD_MASK; c = c->next);

	if (c)
		scratchpad_show_client(c);
	else
		scratchpad_show_first();
}

void
scratchpad_show_client(Client* c)
{
	scratchpad_last_showed = c;
	c->tags = selmon->tagset[selmon->seltags];
	focus(c);
	arrange(selmon);
}

void
scratchpad_show_first(void)
{
	Client *c;
	for (c = selmon->clients; c && c->tags != SCRATCHPAD_MASK; c = c->next);
	if (c)
		scratchpad_show_client(c);
}