-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.c
97 lines (81 loc) · 2.01 KB
/
stack.c
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
#include <stdlib.h>
#include "stack.h"
#include "globals.h"
#include "yawn.h"
void stack_add( xcb_window_t w ) {
struct client_t *c, *tail;
if ( !( c = (struct client_t*)malloc( 1 * sizeof (struct client_t) ) ) ) {
die( "yawn: Malloc error on stack_add" );
}
if ( head == NULL ) {
c->next = NULL;
c->prev = NULL;
c->win = w;
head = c;
}
else {
for ( tail = head; tail->next; tail = tail->next );
c->next = NULL;
c->prev = tail;
c->win = w;
tail->next = c;
}
current = c;
}
void stack_remove( xcb_window_t w ) {
struct client_t * c = stack_get_client( w );
if ( !c ) {
return;
}
if(c->prev == NULL && c->next == NULL) {
free(head);
head = NULL;
current = NULL;
return;
}
if(c->prev == NULL) {
head = c->next;
c->next->prev = NULL;
current = c->next;
}
else if(c->next == NULL) {
c->prev->next = NULL;
current = c->prev;
}
else {
c->prev->next = c->next;
c->next->prev = c->prev;
current = c->prev;
}
free( c );
return;
}
void stack_tile() {
int n = 0, x = 0, y = 0;
struct client_t *c;
if ( current == NULL ) {
return; // nothing to do here
}
for ( c = head; c; c = c->next ) {
++n;
}
printf( "size %i %i %i\n", n, sw, sh );
int w = sw / n;
int h = sh - 2;
for ( c = head; c; c = c->next) {
printf( "yawn: resizing current %i %i %i %i\n", x, y, w, h );
uint32_t values[] = { x, y, w, h };
xcb_configure_window( xconn, c->win, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values );
x += sw / n;
}
xcb_flush( xconn );
}
struct client_t * stack_get_client( xcb_window_t w ) {
struct client_t * c;
for ( c = head; c; c = c->next ) {
if ( c->win == w ) {
return c;
}
}
return NULL;
}