forked from vivien/i3blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.h
83 lines (67 loc) · 2.12 KB
/
block.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
79
80
81
82
83
/*
* block.h - definition of a block
* Copyright (C) 2014 Vivien Didelot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _BLOCK_H
#define _BLOCK_H
#include <sys/types.h>
#include "log.h"
#include "map.h"
#define INTERVAL_ONCE -1
#define INTERVAL_REPEAT -2
#define INTERVAL_PERSIST -3
#define FORMAT_RAW 0
#define FORMAT_JSON 1
/* Block command exit codes */
#define EXIT_URGENT '!' /* 33 */
#define EXIT_ERR_INTERNAL 66
struct block {
struct map *config;
struct map *env;
/* Shortcuts */
const char *command;
int interval;
unsigned signal;
unsigned format;
/* Runtime info */
unsigned long timestamp;
int in[2];
int out[2];
int err[2];
int code;
pid_t pid;
};
const char *block_get(const struct block *block, const char *key);
int block_set(struct block *block, const char *key, const char *value);
static inline const char *block_name(const struct block *block)
{
return block_get(block, "name") ? : "<unknown>";
}
int block_for_each(const struct block *block,
int (*func)(const char *key, const char *value, void *data),
void *data);
#define block_debug(block, msg, ...) \
debug("[%s] " msg, block_name(block), ##__VA_ARGS__)
#define block_error(block, msg, ...) \
error("[%s] " msg, block_name(block), ##__VA_ARGS__)
int block_setup(struct block *block);
int block_click(struct block *block);
int block_spawn(struct block *block);
void block_touch(struct block *block);
int block_reap(struct block *block);
int block_update(struct block *block);
void block_close(struct block *block);
#endif /* _BLOCK_H */