29GMainLoop *mainloop = NULL;
32static bool setup_done =
false;
33char **config_paths = NULL;
40 status.fullscreen = value;
46 status.mouse_over = value;
49 LOG_E(
"Invalid %s enum value in %s:%d for bool type",
"dunst_status", __FILE__, __LINE__);
54void dunst_status_int(
const enum dunst_status_field field,
59 status.pause_level = value;
62 LOG_E(
"Invalid %s enum value in %s:%d for int type",
"dunst_status", __FILE__, __LINE__);
73static gboolean run(
void *data);
92 return "DUNST_WAKEUP";
103 LOG_D(
"Ignoring wake up");
108 run(GINT_TO_POINTER(DUNST_WAKEUP));
111static gboolean run(
void *data)
137 static guint next_timeout_id = 0;
140 LOG_D(
"RUN, reason %i: %s",
reason, dunst_run_reason_str(
reason));
148 if(
reason == DUNST_WAKEUP && next_timeout_id != 0) {
150 g_source_remove(next_timeout_id);
156 return G_SOURCE_REMOVE;
164 if (timeout_at != -1) {
169 gint64 sleep = timeout_at - now;
170 sleep = MAX(sleep, 1000);
172 LOG_D(
"Sleeping for %"G_GINT64_FORMAT
" ms", sleep/1000);
174 next_timeout_id = g_timeout_add(sleep/1000, run, NULL);
182 return G_SOURCE_REMOVE;
185gboolean pause_signal(gpointer data)
192 signal_paused_propertieschanged();
194 return G_SOURCE_CONTINUE;
197gboolean unpause_signal(gpointer data)
201 dunst_status_int(S_PAUSE_LEVEL, 0);
204 signal_paused_propertieschanged();
206 return G_SOURCE_CONTINUE;
209gboolean quit_signal(gpointer data)
212 g_main_loop_quit(mainloop);
214 return G_SOURCE_CONTINUE;
217static void teardown(
void)
225 g_strfreev(config_paths);
227 g_slist_free_full(rules, (GDestroyNotify)rule_free);
230void reload(
char **
const configs)
232 guint
length = g_strv_length(configs);
233 LOG_M(
"Reloading settings (with the %s files)",
length != 0 ?
"new" :
"old");
240 g_slist_free_full(rules, (GDestroyNotify)rule_free);
244 load_settings(
length != 0 ? configs : config_paths);
251 unpause_signal(NULL);
254int dunst_main(
int argc,
char *argv[])
256 dunst_status_int(S_PAUSE_LEVEL, 0);
261 cmdline_load(argc, argv);
265 if (cmdline_get_bool(
"-v/-version/--version",
false,
"Print version")) {
269 char *verbosity = cmdline_get_string(
"-verbosity", NULL,
"Minimum level for message");
273 cmdline_usage_append(
"-conf/-config",
"string",
"Path to configuration file");
275 int start = 1, count = 1;
276 while (cmdline_get_string_offset(
"-conf/-config", NULL, start, &start))
280 config_paths = g_malloc0(
sizeof(
char *) * count);
281 start = 1, count = 0;
285 path = cmdline_get_string_offset(
"-conf/-config", NULL, start, &start);
286 config_paths[count++] = path;
287 }
while (path != NULL);
289 print_notifications = cmdline_get_bool(
"-print/--print",
false,
"Print notifications to stdout");
291 bool startup_notification = cmdline_get_bool(
"-startup_notification/--startup_notification",
292 false,
"Display a notification on startup.");
295 if (cmdline_get_bool(
"-h/-help/--help",
false,
"Print help")) {
299 load_settings(config_paths);
300 int dbus_owner_id = dbus_init();
302 mainloop = g_main_loop_new(NULL, FALSE);
306 guint pause_src = g_unix_signal_add(SIGUSR1, pause_signal, NULL);
307 guint unpause_src = g_unix_signal_add(SIGUSR2, unpause_signal, NULL);
311 guint term_src = g_unix_signal_add(SIGTERM, quit_signal, NULL);
312 guint int_src = g_unix_signal_add(SIGINT, quit_signal, NULL);
315 if (startup_notification) {
318 n->appname = g_strdup(
"dunst");
319 n->summary = g_strdup(
"startup");
320 n->body = g_strdup(
"dunst is up and running");
323 n->markup = MARKUP_NO;
331 run(GINT_TO_POINTER(DUNST_TIMER));
335 dunst_status_int(S_PAUSE_LEVEL,
settings.default_pause_level);
337 g_main_loop_run(mainloop);
338 g_clear_pointer(&mainloop, g_main_loop_unref);
341 g_source_remove(pause_src);
342 g_source_remove(unpause_src);
343 g_source_remove(term_src);
344 g_source_remove(int_src);
346 dbus_teardown(dbus_owner_id);
355void usage(
int exit_status)
358 const char *us = cmdline_create_usage();
363void print_version(
void)
365 printf(
"Dunst - A customizable and lightweight notification-daemon %s\n", VERSION);
367 printf(
"Compiled on %s with the following options:\n",
STR_TO(_CCDATE));
370 printf(
"X11 support: %s\n", X11_SUPPORT ?
"enabled" :
"disabled");
371 printf(
"Wayland support: %s\n", WAYLAND_SUPPORT ?
"enabled" :
"disabled");
372 printf(
"SYSCONFDIR set to: %s\n",
SYSCONFDIR);
375 printf(
"Compiler flags: %s\n",
STR_TO(_CFLAGS));
378 printf(
"Linker flags: %s\n",
STR_TO(_LDFLAGS));
DBus support and implementation of the Desktop Notifications Specification.
reason
The reasons according to the notification spec.
Layout and render notifications.
dunst_run_reason
The reason for which the run function was invoked.
void dunst_status(const enum dunst_status_field field, bool value)
Modify the current status of dunst.
#define MAX_PAUSE_LEVEL
A structure to describe dunst's global window status.
void log_set_level_from_string(const char *level)
Set the current loglevel to level
void dunst_log_init(enum log_mask mask)
Initialise log handling.
Logging subsystem and helpers.
#define LOG_E
Prefix message with "[<source path>:<function name>:<line number>] ".
void notification_init(struct notification *n)
Sanitize values of notification, apply all matching rules and generate derived fields.
struct notification * notification_create(void)
Create notification struct and initialise all fields with either.
Notification type definitions.
Parser for settings and cmdline arguments.
int queues_notification_insert(struct notification *n)
Insert a fully initialized notification into queues.
void queues_init(void)
Initialise necessary queues.
void queues_teardown(void)
Remove all notifications from all list and free the notifications.
gint64 queues_get_next_datachange(gint64 time)
Calculate the distance to the next event, when an element in the queues changes.
void queues_reapply_all_rules(void)
Reapply all rules to the queue (used when reloading configs)
unsigned int queues_length_displayed(void)
Returns the current amount of notifications, which are shown in the UI.
void queues_update(struct dunst_status status, gint64 time)
Move inserted notifications from waiting queue to displayed queue and show them.
Queues for history, waiting and displayed notifications.
Rules managment and helpers.
#define SYSCONFDIR
Since this gets defined by $DEFAULT_CPPFLAGS at compile time doxygen seems to miss the correct value.
Type definitions for settings.
int progress
percentage (-1: undefined)
gint64 timeout
time to display (in milliseconds)
gint64 time_monotonic_now(void)
Get the current monotonic time.
String, time and other various helpers.
#define S2US(s)
Convert seconds into microseconds.
#define STR_TO(...)
Stringify the given expression or macro.