-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwindow_list.h
78 lines (62 loc) · 1.34 KB
/
window_list.h
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
#include <stdbool.h>
#include <stdlib.h>
#include <X11/Xlib.h>
struct window_list_node {
Window w;
struct window_list_node* next;
};
struct window_list {
struct window_list_node* root;
};
typedef struct window_list window_list;
typedef struct window_list_node window_list_node;
window_list* wl_init()
{
window_list* wl = malloc(sizeof(window_list));
wl->root = NULL;
return wl;
}
void wl_add(window_list *wl, Window w)
{
window_list_node* node;
node = malloc(sizeof(window_list_node));
node->w = w;
node->next = wl->root;
wl->root = node;
}
void wl_delete(window_list *wl, Window w)
{
window_list_node **node, *tmp;
node = &wl->root;
while (*node) {
if ((*node)->w == w) {
tmp = *node;
*node = ((*node)->next);
free(tmp);
} else {
node = &((*node)->next);
}
}
}
bool wl_find(window_list *wl, Window w)
{
window_list_node *node;
node = wl->root;
while (node) {
if (node->w == w)
return true;
node = node->next;
}
return false;
}
Window wl_next(window_list *wl, Window w)
{
window_list_node *node;
node = wl->root;
while (node) {
if (node->w == w)
return (node->next) ? node->next->w : wl->root->w;
node = node->next;
}
return w;
}