-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathmain.c
119 lines (105 loc) · 4.21 KB
/
main.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#define _POSIX_C_SOURCE 200809L
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "dbus.h"
#include "mako.h"
#include "notification.h"
#include "render.h"
#include "wayland.h"
static const char usage[] =
"Usage: mako [options...]\n"
"\n"
" -h, --help Show help message and quit.\n"
" -c, --config <path> Path to config file.\n"
" --font <font> Font family and size.\n"
" --background-color <color> Background color.\n"
" --text-color <color> Text color.\n"
" --width <px> Notification width.\n"
" --height <px> Max notification height.\n"
" --margin <px>[,<px>...] Margin values, comma separated.\n"
" Up to four values, with the same\n"
" meaning as in CSS.\n"
" --padding <px>[,<px>...] Padding values, comma separated.\n"
" Up to four values, with the same\n"
" meaning as in CSS.\n"
" --border-size <px> Border size.\n"
" --border-color <color> Border color.\n"
" --border-radius <px> Corner radius\n"
" --progress-color <color> Progress indicator color.\n"
" --icons <0|1> Show icons in notifications.\n"
" --icon-path <path>[:<path>...] Icon search path, colon delimited.\n"
" --max-icon-size <px> Set max size of icons.\n"
" --markup <0|1> Enable/disable markup.\n"
" --actions <0|1> Enable/disable application action\n"
" execution.\n"
" --format <format> Format string.\n"
" --hidden-format <format> Format string.\n"
" --max-visible <n> Max number of visible notifications.\n"
" --max-history <n> Max size of history buffer.\n"
" --history <0|1> Add expired notificatinos to history.\n"
" --sort <sort_criteria> Sorts incoming notifications by time\n"
" and/or priority in ascending(+) or\n"
" descending(-) order.\n"
" --default-timeout <timeout> Default timeout in milliseconds.\n"
" --ignore-timeout <0|1> Enable/disable notification timeout.\n"
" --output <name> Show notifications on this output.\n"
" --layer <layer> Arrange notifications at this layer.\n"
" --anchor <position> Position on output to put notifications.\n"
"\n"
"Colors can be specified with the format #RRGGBB or #RRGGBBAA.\n";
static bool init(struct mako_state *state) {
if (!init_dbus(state)) {
return false;
}
if (!init_wayland(state)) {
finish_dbus(state);
return false;
}
if (!init_event_loop(&state->event_loop, state->bus, state->display)) {
finish_dbus(state);
finish_wayland(state);
return false;
}
wl_list_init(&state->notifications);
wl_list_init(&state->history);
return true;
}
static void finish(struct mako_state *state) {
struct mako_notification *notif, *tmp;
wl_list_for_each_safe(notif, tmp, &state->notifications, link) {
destroy_notification(notif);
}
wl_list_for_each_safe(notif, tmp, &state->history, link) {
destroy_notification(notif);
}
finish_event_loop(&state->event_loop);
finish_wayland(state);
finish_dbus(state);
}
static struct mako_event_loop *event_loop = NULL;
int main(int argc, char *argv[]) {
struct mako_state state = {0};
state.argc = argc;
state.argv = argv;
// This is a bit wasteful, but easier than special-casing the reload.
init_default_config(&state.config);
int ret = reload_config(&state.config, argc, argv);
if (ret < 0) {
return EXIT_FAILURE;
} else if (ret > 0) {
printf("%s", usage);
return EXIT_SUCCESS;
}
if (!init(&state)) {
finish_config(&state.config);
return EXIT_FAILURE;
}
event_loop = &state.event_loop;
ret = run_event_loop(&state.event_loop);
finish(&state);
finish_config(&state.config);
return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}