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
|
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <stdlib.h>
#include "bardata.h"
#include "pipe.h"
int fontsize = 16;
color_t default_fg, default_bg;
int bar_height = 20;
// Global state, oh naur D:
comp_t comps[32];
size_t comps_size = 0;
comp_t *comps_left[16], *comps_right[16], *comps_center[16];
size_t left_size = 0, right_size = 0, center_size = 0;
void new_component(char *name) {
strcpy(comps[comps_size].name, name);
comps_size++;
}
comp_t *find_comp(char *name) {
for (size_t i = 0; i < comps_size; i++) {
if (strcmp(comps[i].name, name) == 0) {
return &comps[i];
}
}
return NULL;
}
void add_component(comp_side_t side, char *name) {
comp_t *comp = find_comp(name);
if (side == SIDE_LEFT) {
comps_left[left_size] = comp;
left_size++;
return;
}
if (side == SIDE_RIGHT) {
comps_right[right_size] = comp;
right_size++;
return;
}
if (side == SIDE_CENTER) {
comps_center[center_size] = comp;
center_size++;
return;
}
}
void set_layout(char argv[MAX_ARGS][MAX_ARG_LEN], int argc) {
comp_side_t side = SIDE_LEFT;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-left") == 0) {
side = SIDE_LEFT;
continue;
}
if (strcmp(argv[i], "-center") == 0) {
side = SIDE_CENTER;
continue;
}
if (strcmp(argv[i], "-right") == 0) {
side = SIDE_RIGHT;
continue;
}
add_component(side, argv[i]);
}
}
void set_var(char argv[MAX_ARGS][MAX_ARG_LEN], int argc) {
char *var = argv[1];
if (strcmp(var, "height")) {
bar_height = atoi(argv[2]);
}
if (strcmp(var, "fontsize")) {
fontsize = atoi(argv[2]);
}
}
|