Force management of queues to queues.c

This commit is contained in:
Benedikt Heine 2017-10-11 12:25:30 +02:00
parent e3881766c0
commit a536e3f60b
5 changed files with 51 additions and 24 deletions

View File

@ -60,11 +60,11 @@ gboolean run(void *data)
timeout_cnt--; timeout_cnt--;
} }
if (displayed->length > 0 && !xctx.visible) { if (queues_length_displayed() > 0 && !xctx.visible) {
x_win_show(); x_win_show();
} }
if (xctx.visible && displayed->length == 0) { if (xctx.visible && queues_length_displayed() == 0) {
x_win_hide(); x_win_hide();
} }

View File

@ -137,7 +137,7 @@ void invoke_action(const char *action)
int appname_len = strlen(appname_begin) - 1; // remove ] int appname_len = strlen(appname_begin) - 1; // remove ]
int action_len = strlen(action) - appname_len - 3; // remove space, [, ] int action_len = strlen(action) - appname_len - 3; // remove space, [, ]
for (GList *iter = g_queue_peek_head_link(displayed); iter; for (const GList *iter = queues_get_displayed(); iter;
iter = iter->next) { iter = iter->next) {
notification *n = iter->data; notification *n = iter->data;
if (g_str_has_prefix(appname_begin, n->appname) && strlen(n->appname) == appname_len) { if (g_str_has_prefix(appname_begin, n->appname) && strlen(n->appname) == appname_len) {
@ -189,7 +189,7 @@ void context_menu(void)
} }
char *dmenu_input = NULL; char *dmenu_input = NULL;
for (GList *iter = g_queue_peek_head_link(displayed); iter; for (const GList *iter = queues_get_displayed(); iter;
iter = iter->next) { iter = iter->next) {
notification *n = iter->data; notification *n = iter->data;

View File

@ -10,9 +10,9 @@
#include "settings.h" #include "settings.h"
/* notification lists */ /* notification lists */
GQueue *queue = NULL; /* all new notifications get into here */ static GQueue *queue = NULL; /* all new notifications get into here */
GQueue *displayed = NULL; /* currently displayed notifications */ static GQueue *displayed = NULL; /* currently displayed notifications */
GQueue *history = NULL; /* history of displayed notifications */ static GQueue *history = NULL; /* history of displayed notifications */
unsigned int displayed_limit = 0; unsigned int displayed_limit = 0;
int next_notification_id = 1; int next_notification_id = 1;
@ -32,6 +32,24 @@ void queues_displayed_limit(unsigned int limit)
displayed_limit = limit; displayed_limit = limit;
} }
/* misc getter functions */
const GList *queues_get_displayed()
{
return g_queue_peek_head_link(displayed);
}
unsigned int queues_length_waiting()
{
return queue->length;
}
unsigned int queues_length_displayed()
{
return displayed->length;
}
unsigned int queues_length_history()
{
return history->length;
}
int queues_notification_insert(notification *n, int replaces_id) int queues_notification_insert(notification *n, int replaces_id)
{ {
if (replaces_id == 0) { if (replaces_id == 0) {

View File

@ -5,11 +5,6 @@
#include "notification.h" #include "notification.h"
extern GQueue *queue;
extern GQueue *displayed;
extern GQueue *history;
extern unsigned int displayed_limit;
/* /*
* Initialise neccessary queues * Initialise neccessary queues
*/ */
@ -21,6 +16,19 @@ void queues_init(void);
*/ */
void queues_displayed_limit(unsigned int limit); void queues_displayed_limit(unsigned int limit);
/*
* Return read only list of notifications
*/
const GList *queues_get_displayed();
/*
* Returns the current amount of notifications,
* which are shown, waiting or already in history
*/
unsigned int queues_length_waiting();
unsigned int queues_length_displayed();
unsigned int queues_length_history();
/* /*
* Insert a fully initialized notification into queues * Insert a fully initialized notification into queues
* Respects stack_duplicates, and notification replacement * Respects stack_duplicates, and notification replacement
@ -43,9 +51,12 @@ int queues_notification_insert(notification *n, int replaces_id);
bool queues_notification_replace_id(notification *new); bool queues_notification_replace_id(notification *new);
/* /*
* Close the notification that has id. * Close the notification that has n->id == id
* *
* After closing, call wake_up to remove the notification from UI * Sends a signal and pushes it automatically to history.
*
* After closing, call wake_up to synchronize the queues with the UI
* (which closes the notification on screen)
* *
* reasons: * reasons:
* -1 -> notification is a replacement, no NotificationClosed signal emitted * -1 -> notification is a replacement, no NotificationClosed signal emitted

View File

@ -533,11 +533,11 @@ static GSList *r_create_layouts(cairo_t *c)
{ {
GSList *layouts = NULL; GSList *layouts = NULL;
int qlen = g_list_length(g_queue_peek_head_link(queue)); int qlen = queues_length_waiting();
bool xmore_is_needed = qlen > 0 && settings.indicate_hidden; bool xmore_is_needed = qlen > 0 && settings.indicate_hidden;
notification *last = NULL; notification *last = NULL;
for (GList *iter = g_queue_peek_head_link(displayed); for (const GList *iter = queues_get_displayed();
iter; iter = iter->next) iter; iter = iter->next)
{ {
notification *n = iter->data; notification *n = iter->data;
@ -854,14 +854,12 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback,
&& XLookupKeysym(&ev.xkey, && XLookupKeysym(&ev.xkey,
0) == settings.close_ks.sym 0) == settings.close_ks.sym
&& settings.close_ks.mask == state) { && settings.close_ks.mask == state) {
if (displayed) { const GList *displayed = queues_get_displayed();
notification *n = g_queue_peek_head(displayed); if (displayed && displayed->data) {
if (n) { queues_notification_close(displayed->data, 2);
queues_notification_close(n, 2);
wake_up(); wake_up();
} }
} }
}
if (settings.history_ks.str if (settings.history_ks.str
&& XLookupKeysym(&ev.xkey, && XLookupKeysym(&ev.xkey,
0) == settings.history_ks.sym 0) == settings.history_ks.sym
@ -926,7 +924,7 @@ static void x_handle_click(XEvent ev)
int y = settings.separator_height; int y = settings.separator_height;
notification *n = NULL; notification *n = NULL;
int first = true; int first = true;
for (GList *iter = g_queue_peek_head_link(displayed); iter; for (const GList *iter = queues_get_displayed(); iter;
iter = iter->next) { iter = iter->next) {
n = iter->data; n = iter->data;
if (ev.xbutton.y > y && ev.xbutton.y < y + n->displayed_height) if (ev.xbutton.y > y && ev.xbutton.y < y + n->displayed_height)
@ -1127,7 +1125,7 @@ static void x_win_setup(void)
void x_win_show(void) void x_win_show(void)
{ {
/* window is already mapped or there's nothing to show */ /* window is already mapped or there's nothing to show */
if (xctx.visible || g_queue_is_empty(displayed)) { if (xctx.visible || queues_length_displayed() == 0) {
return; return;
} }