4 #include <xcb/xcb_event.h>
11 node_t *make_node(void)
13 node_t *n = malloc(sizeof(node_t));
14 n->parent = n->first_child = n->second_child = NULL;
15 n->split_ratio = split_ratio;
16 n->split_type = TYPE_VERTICAL;
17 n->birth_rotation = ROTATE_IDENTITY;
23 monitor_t *make_monitor(xcb_rectangle_t *rect)
25 monitor_t *m = malloc(sizeof(monitor_t));
26 snprintf(m->name, sizeof(m->name), "%s%02d", DEFAULT_MON_NAME, ++monitor_uid);
27 m->prev = m->next = NULL;
28 m->desk = m->last_desk = NULL;
32 warn("no rectangle was given for monitor '%s'\n", m->name);
33 m->top_padding = m->right_padding = m->bottom_padding = m->left_padding = 0;
38 monitor_t *find_monitor(char *name)
40 for (monitor_t *m = mon_head; m != NULL; m = m->next)
41 if (strcmp(m->name, name) == 0)
46 monitor_t *get_monitor_by_id(xcb_randr_output_t id)
48 for (monitor_t *m = mon_head; m != NULL; m = m->next)
54 monitor_t *add_monitor(xcb_rectangle_t *rect)
56 monitor_t *m = make_monitor(rect);
70 void remove_monitor(monitor_t *m)
72 while (m->desk_head != NULL)
73 remove_desktop(m, m->desk_head);
74 monitor_t *prev = m->prev;
75 monitor_t *next = m->next;
88 void transfer_desktops(monitor_t *dst, monitor_t *src)
90 if (dst == NULL || src == NULL)
92 dst->desk_tail->next = src->desk_head;
93 src->desk_head->prev = dst->desk_tail;
94 dst->desk_tail = src->desk_tail;
95 src->desk = src->last_desk = src->desk_head = src->desk_tail = NULL;
99 desktop_t *make_desktop(const char *name)
101 desktop_t *d = malloc(sizeof(desktop_t));
103 snprintf(d->name, sizeof(d->name), "%s%02d", DEFAULT_DESK_NAME, ++desktop_uid);
105 strncpy(d->name, name, sizeof(d->name));
106 d->layout = LAYOUT_TILED;
107 d->prev = d->next = NULL;
108 d->root = d->focus = NULL;
109 d->history = make_focus_history();
113 void add_desktop(monitor_t *m, char *name)
115 desktop_t *d = make_desktop(name);
116 if (m->desk == NULL) {
121 m->desk_tail->next = d;
122 d->prev = m->desk_tail;
126 ewmh_update_number_of_desktops();
127 ewmh_update_desktop_names();
131 void empty_desktop(desktop_t *d)
133 destroy_tree(d->root);
134 d->root = d->focus = NULL;
135 empty_history(d->history);
138 void remove_desktop(monitor_t *m, desktop_t *d)
141 desktop_t *prev = d->prev;
142 desktop_t *next = d->next;
147 if (d == m->desk_head)
149 if (d == m->desk_tail)
155 client_t *make_client(xcb_window_t win)
157 client_t *c = malloc(sizeof(client_t));
158 strncpy(c->class_name, MISSING_VALUE, sizeof(c->class_name));
159 c->uid = ++client_uid;
160 c->border_width = border_width;
162 c->floating = c->transient = c->fullscreen = c->locked = c->urgent = false;
166 rule_t *make_rule(void)
168 rule_t *r = malloc(sizeof(rule_t));
170 r->effect.floating = false;
171 r->effect.follow = false;
172 r->effect.monitor = NULL;
173 r->effect.desktop = NULL;
179 pointer_state_t *make_pointer_state(void)
181 pointer_state_t *p = malloc(sizeof(pointer_state_t));
184 p->node = p->vertical_fence = p->horizontal_fence = NULL;
186 p->window = XCB_NONE;
190 focus_history_t *make_focus_history(void)
192 focus_history_t *f = malloc(sizeof(focus_history_t));
193 f->head = f->tail = NULL;
197 node_list_t *make_node_list(void)
199 node_list_t *n = malloc(sizeof(node_list_t));
201 n->prev = n->next = NULL;
206 void history_add(focus_history_t *f, node_t *n)
208 node_list_t *a = make_node_list();
210 if (f->head == NULL) {
211 f->head = f->tail = a;
212 } else if (f->head->node != n) {
213 for (node_list_t *b = f->head; b != NULL; b = b->next)
224 void history_remove(focus_history_t *f, node_t *n)
226 /* in order to maintain the `latest` node list state,
227 we remove node lists from head to tail */
228 node_list_t *b = f->head;
231 node_list_t *a = b->prev;
232 node_list_t *c = b->next;
234 /* remove duplicate entries */
235 while (c != NULL && c->node == a->node) {
236 node_list_t *d = c->next;
258 void empty_history(focus_history_t *f)
260 node_list_t *a = f->head;
262 node_list_t *b = a->next;
266 f->head = f->tail = NULL;
269 node_t *history_get(focus_history_t *f, int i)
271 node_list_t *a = f->head;
272 while (a != NULL && i > 0) {