Dunst
Lightweight notification daemon
Loading...
Searching...
No Matches
queues.c File Reference
#include <assert.h>
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include "queues.h"
#include "dunst.h"
#include "log.h"
#include "notification.h"
#include "settings.h"
#include "utils.h"
#include "rules.h"
+ Include dependency graph for queues.c:

Go to the source code of this file.

Functions

static bool queues_stack_duplicate (struct notification *new)
 Replaces duplicate notification and stacks it.
 
static bool queues_stack_by_tag (struct notification *new)
 Replaces the first notification of the same stack_tag.
 
void queues_init (void)
 Initialise necessary queues.
 
GList * queues_get_displayed (void)
 Receive the current list of displayed notifications.
 
struct notificationqueues_get_head_waiting (void)
 Get the highest notification in line.
 
unsigned int queues_length_waiting (void)
 Returns the current amount of notifications, which are waiting to get displayed.
 
unsigned int queues_length_displayed (void)
 Returns the current amount of notifications, which are shown in the UI.
 
unsigned int queues_length_history (void)
 Returns the current amount of notifications, which are already in history.
 
GList * queues_get_history (void)
 Recieve the list of all notifications encountered.
 
static void queues_swap_notifications (GQueue *queueA, GList *elemA, GQueue *queueB, GList *elemB)
 Swap two given queue elements.
 
static bool queues_notification_is_ready (const struct notification *n, struct dunst_status status, bool shown)
 Check if a notification is eligible to get shown.
 
static bool queues_notification_is_finished (struct notification *n, struct dunst_status status, gint64 time)
 Check if a notification has timed out.
 
int queues_notification_insert (struct notification *n)
 Insert a fully initialized notification into queues.
 
bool queues_notification_replace_id (struct notification *new)
 Replace the notification which matches the id field of the new notification.
 
void queues_notification_close_id (gint id, enum reason reason)
 Close the notification that has n->id == id.
 
void queues_notification_close (struct notification *n, enum reason reason)
 Close the given notification.
 
void queues_notification_remove (struct notification *n, enum reason reason)
 Remove the given notification from all queues.
 
static void queues_destroy_notification (struct notification *n, gpointer user_data)
 
guint queues_history_clear (void)
 Removes all notifications from history Returns the number of removed notifications.
 
void queues_history_pop (void)
 Pushes the latest notification of history to the displayed queue and removes it from history.
 
void queues_history_pop_by_id (gint id)
 Pushes the latest notification found in the history buffer identified by it's assigned id.
 
void queues_history_push (struct notification *n)
 Push a single notification to history The given notification has to be removed its queue.
 
void queues_history_push_all (void)
 Push all waiting and displayed notifications to history.
 
bool queues_history_remove_by_id (gint id)
 Removes an notification identified by the given id from the history.
 
void queues_update (struct dunst_status status, gint64 time)
 Move inserted notifications from waiting queue to displayed queue and show them.
 
gint64 queues_get_next_datachange (gint64 time)
 Calculate the distance to the next event, when an element in the queues changes.
 
struct notificationqueues_get_by_id (gint id)
 Get the notification which has the given id in the displayed and waiting queue or NULL if not found.
 
void queues_reapply_all_rules (void)
 Reapply all rules to the queue (used when reloading configs)
 
static void teardown_notification (gpointer data)
 Helper function for queues_teardown() to free a single notification.
 
void queues_teardown (void)
 Remove all notifications from all list and free the notifications.
 

Variables

static GQueue * waiting = NULL
 all new notifications get into here
 
static GQueue * displayed = NULL
 currently displayed notifications
 
static GQueue * history = NULL
 history of displayed notifications
 
int next_notification_id = 1
 

Detailed Description

License
BSD-3-Clause

Definition in file queues.c.

Function Documentation

◆ queues_destroy_notification()

static void queues_destroy_notification ( struct notification * n,
gpointer user_data )
static

Definition at line 393 of file queues.c.

◆ queues_get_by_id()

struct notification * queues_get_by_id ( gint id)

Get the notification which has the given id in the displayed and waiting queue or NULL if not found.

Parameters
idthe id searched for.
Returns
the id notification or NULL

Definition at line 662 of file queues.c.

◆ queues_get_displayed()

GList * queues_get_displayed ( void )

Receive the current list of displayed notifications.

Returns
read only list of notifications

Definition at line 41 of file queues.c.

◆ queues_get_head_waiting()

struct notification * queues_get_head_waiting ( void )

Get the highest notification in line.

Returns
the first notification in waiting
Return values
NULLif waiting is empty

Definition at line 47 of file queues.c.

◆ queues_get_history()

GList * queues_get_history ( void )

Recieve the list of all notifications encountered.

Returns
read only list of notifications

Definition at line 73 of file queues.c.

◆ queues_get_next_datachange()

gint64 queues_get_next_datachange ( gint64 time)

Calculate the distance to the next event, when an element in the queues changes.

Parameters
timethe current time
Returns
the timestamp of the next event in the queue, which forces an update visible to the user. This may be:
  • notification hits timeout
  • notification's age second changes
  • notification's age threshold is hit

Definition at line 620 of file queues.c.

◆ queues_history_clear()

guint queues_history_clear ( void )

Removes all notifications from history Returns the number of removed notifications.

Definition at line 400 of file queues.c.

◆ queues_history_pop()

void queues_history_pop ( void )

Pushes the latest notification of history to the displayed queue and removes it from history.

Definition at line 409 of file queues.c.

◆ queues_history_pop_by_id()

void queues_history_pop_by_id ( gint id)

Pushes the latest notification found in the history buffer identified by it's assigned id.

Definition at line 421 of file queues.c.

◆ queues_history_push()

void queues_history_push ( struct notification * n)

Push a single notification to history The given notification has to be removed its queue.

Parameters
n(transfer full) The notification to push to history

Definition at line 449 of file queues.c.

◆ queues_history_push_all()

void queues_history_push_all ( void )

Push all waiting and displayed notifications to history.

Definition at line 465 of file queues.c.

◆ queues_history_remove_by_id()

bool queues_history_remove_by_id ( gint id)

Removes an notification identified by the given id from the history.

Definition at line 477 of file queues.c.

◆ queues_init()

void queues_init ( void )

Initialise necessary queues.

Precondition
Do not call consecutively to avoid memory leaks or assure to have queues_teardown() executed before

Definition at line 33 of file queues.c.

◆ queues_length_displayed()

unsigned int queues_length_displayed ( void )

Returns the current amount of notifications, which are shown in the UI.

Definition at line 61 of file queues.c.

◆ queues_length_history()

unsigned int queues_length_history ( void )

Returns the current amount of notifications, which are already in history.

Definition at line 67 of file queues.c.

◆ queues_length_waiting()

unsigned int queues_length_waiting ( void )

Returns the current amount of notifications, which are waiting to get displayed.

Definition at line 55 of file queues.c.

◆ queues_notification_close()

void queues_notification_close ( struct notification * n,
enum reason reason )

Close the given notification.

See also
queues_notification_close_id()
Parameters
n(transfer full) The notification to close
reasonThe reason to close

Definition at line 380 of file queues.c.

◆ queues_notification_close_id()

void queues_notification_close_id ( gint id,
enum reason reason )

Close the notification that has n->id == id.

Sends a signal and pushes the selected notification automatically to history.

Parameters
idThe id of the notification to close
reasonThe reason to close
Postcondition
Call wake_up() to synchronize the queues with the UI (which closes the notification on screen)

Definition at line 354 of file queues.c.

◆ queues_notification_insert()

int queues_notification_insert ( struct notification * n)

Insert a fully initialized notification into queues.

Respects stack_duplicates, and notification replacement

Parameters
nthe notification to insert
  • If n->id != 0, n replaces notification n with id n->id
  • If n->id == 0, n gets a new id assigned
Returns
The new value of n->id
Return values
0if the notification was dismissed and freed

Definition at line 169 of file queues.c.

◆ queues_notification_is_finished()

static bool queues_notification_is_finished ( struct notification * n,
struct dunst_status status,
gint64 time )
static

Check if a notification has timed out.

Parameters
nthe notification to check
statusthe current status of dunst
timethe current time
Return values
truethe notification is timed out
falseotherwise

Definition at line 136 of file queues.c.

◆ queues_notification_is_ready()

static bool queues_notification_is_ready ( const struct notification * n,
struct dunst_status status,
bool shown )
static

Check if a notification is eligible to get shown.

Parameters
nThe notification to check
statusThe current status of dunst
shownTrue if the notification is currently displayed

Definition at line 113 of file queues.c.

◆ queues_notification_remove()

void queues_notification_remove ( struct notification * n,
enum reason reason )

Remove the given notification from all queues.

Sends a signal and removes the selected notification from all queues.

Parameters
n(transfer full) The notification to remove
reasonThe reason to remove

Definition at line 386 of file queues.c.

◆ queues_notification_replace_id()

bool queues_notification_replace_id ( struct notification * new)

Replace the notification which matches the id field of the new notification.

The given notification is inserted right in the same position as the old notification.

Parameters
newreplacement for the old notification
Return values
trueif a matching notification has been found and is replaced
falseotherwise

Definition at line 328 of file queues.c.

◆ queues_reapply_all_rules()

void queues_reapply_all_rules ( void )

Reapply all rules to the queue (used when reloading configs)

Definition at line 679 of file queues.c.

◆ queues_stack_by_tag()

static bool queues_stack_by_tag ( struct notification * new)
static

Replaces the first notification of the same stack_tag.

Return values
truenotification got stacked
falsenotification did not get stacked

Definition at line 280 of file queues.c.

◆ queues_stack_duplicate()

static bool queues_stack_duplicate ( struct notification * new)
static

Replaces duplicate notification and stacks it.

Return values
truenotification got stacked
falsenotification did not get stacked

Definition at line 221 of file queues.c.

◆ queues_swap_notifications()

static void queues_swap_notifications ( GQueue * queueA,
GList * elemA,
GQueue * queueB,
GList * elemB )
static

Swap two given queue elements.

The element's data has to be a notification.

Precondition
{ elemA has to be part of queueA. }
{ elemB has to be part of queueB. }
Parameters
queueAThe queue, which elemB's data will get inserted
elemAThe element, which will get removed from queueA
queueBThe queue, which elemA's data will get inserted
elemBThe element, which will get removed from queueB

Definition at line 89 of file queues.c.

◆ queues_teardown()

void queues_teardown ( void )

Remove all notifications from all list and free the notifications.

Precondition
At least one time queues_init() called

Definition at line 706 of file queues.c.

◆ queues_update()

void queues_update ( struct dunst_status status,
gint64 time )

Move inserted notifications from waiting queue to displayed queue and show them.

In displayed queue, the amount of elements is limited to the amount set via queues_displayed_limit()

Postcondition
Call wake_up() to synchronize the queues with the UI (which closes old and shows new notifications on screen)
Parameters
statusthe current status of dunst
timethe current time

Definition at line 501 of file queues.c.

◆ teardown_notification()

static void teardown_notification ( gpointer data)
static

Helper function for queues_teardown() to free a single notification.

Parameters
dataThe notification to free

Definition at line 699 of file queues.c.

Variable Documentation

◆ displayed

GQueue* displayed = NULL
static

currently displayed notifications

Definition at line 24 of file queues.c.

◆ history

GQueue* history = NULL
static

history of displayed notifications

Definition at line 25 of file queues.c.

◆ next_notification_id

int next_notification_id = 1

Definition at line 27 of file queues.c.

◆ waiting

GQueue* waiting = NULL
static

all new notifications get into here

Definition at line 23 of file queues.c.