When traversing both queues, traverse in one loop
On actions, where waiting and displayed has to get traversed, traverse them both in a single loop. Code duplication isn't necessary anymore.
This commit is contained in:
parent
34e97b3e94
commit
e1ee87b5d3
136
src/queues.c
136
src/queues.c
@ -169,52 +169,31 @@ int queues_notification_insert(notification *n)
|
|||||||
*/
|
*/
|
||||||
static bool queues_stack_duplicate(notification *n)
|
static bool queues_stack_duplicate(notification *n)
|
||||||
{
|
{
|
||||||
for (GList *iter = g_queue_peek_head_link(displayed); iter;
|
GQueue *allqueues[] = { displayed, waiting };
|
||||||
iter = iter->next) {
|
for (int i = 0; i < sizeof(allqueues)/sizeof(GList*); i++) {
|
||||||
notification *orig = iter->data;
|
for (GList *iter = g_queue_peek_head_link(allqueues[i]); iter;
|
||||||
if (notification_is_duplicate(orig, n)) {
|
iter = iter->next) {
|
||||||
/* If the progress differs, probably notify-send was used to update the notification
|
notification *orig = iter->data;
|
||||||
* So only count it as a duplicate, if the progress was not the same.
|
if (notification_is_duplicate(orig, n)) {
|
||||||
* */
|
/* If the progress differs, probably notify-send was used to update the notification
|
||||||
if (orig->progress == n->progress) {
|
* So only count it as a duplicate, if the progress was not the same.
|
||||||
orig->dup_count++;
|
* */
|
||||||
} else {
|
if (orig->progress == n->progress) {
|
||||||
orig->progress = n->progress;
|
orig->dup_count++;
|
||||||
|
} else {
|
||||||
|
orig->progress = n->progress;
|
||||||
|
}
|
||||||
|
iter->data = n;
|
||||||
|
|
||||||
|
n->dup_count = orig->dup_count;
|
||||||
|
signal_notification_closed(orig, 1);
|
||||||
|
|
||||||
|
if ( allqueues[i] == displayed )
|
||||||
|
n->start = time_monotonic_now();
|
||||||
|
|
||||||
|
notification_free(orig);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
iter->data = n;
|
|
||||||
|
|
||||||
n->start = time_monotonic_now();
|
|
||||||
|
|
||||||
n->dup_count = orig->dup_count;
|
|
||||||
|
|
||||||
signal_notification_closed(orig, 1);
|
|
||||||
|
|
||||||
notification_free(orig);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (GList *iter = g_queue_peek_head_link(waiting); iter;
|
|
||||||
iter = iter->next) {
|
|
||||||
notification *orig = iter->data;
|
|
||||||
if (notification_is_duplicate(orig, n)) {
|
|
||||||
/* If the progress differs, probably notify-send was used to update the notification
|
|
||||||
* So only count it as a duplicate, if the progress was not the same.
|
|
||||||
* */
|
|
||||||
if (orig->progress == n->progress) {
|
|
||||||
orig->dup_count++;
|
|
||||||
} else {
|
|
||||||
orig->progress = n->progress;
|
|
||||||
}
|
|
||||||
iter->data = n;
|
|
||||||
|
|
||||||
n->dup_count = orig->dup_count;
|
|
||||||
|
|
||||||
signal_notification_closed(orig, 1);
|
|
||||||
|
|
||||||
notification_free(orig);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,31 +203,26 @@ static bool queues_stack_duplicate(notification *n)
|
|||||||
/* see queues.h */
|
/* see queues.h */
|
||||||
bool queues_notification_replace_id(notification *new)
|
bool queues_notification_replace_id(notification *new)
|
||||||
{
|
{
|
||||||
|
GQueue *allqueues[] = { displayed, waiting };
|
||||||
|
for (int i = 0; i < sizeof(allqueues)/sizeof(GList*); i++) {
|
||||||
|
for (GList *iter = g_queue_peek_head_link(allqueues[i]);
|
||||||
|
iter;
|
||||||
|
iter = iter->next) {
|
||||||
|
notification *old = iter->data;
|
||||||
|
if (old->id == new->id) {
|
||||||
|
iter->data = new;
|
||||||
|
new->dup_count = old->dup_count;
|
||||||
|
|
||||||
for (GList *iter = g_queue_peek_head_link(displayed);
|
if ( allqueues[i] == displayed ) {
|
||||||
iter;
|
new->start = time_monotonic_now();
|
||||||
iter = iter->next) {
|
notification_run_script(new);
|
||||||
notification *old = iter->data;
|
}
|
||||||
if (old->id == new->id) {
|
|
||||||
iter->data = new;
|
|
||||||
new->start = time_monotonic_now();
|
|
||||||
new->dup_count = old->dup_count;
|
|
||||||
notification_run_script(new);
|
|
||||||
notification_free(old);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (GList *iter = g_queue_peek_head_link(waiting);
|
notification_free(old);
|
||||||
iter;
|
return true;
|
||||||
iter = iter->next) {
|
}
|
||||||
notification *old = iter->data;
|
|
||||||
if (old->id == new->id) {
|
|
||||||
iter->data = new;
|
|
||||||
new->dup_count = old->dup_count;
|
|
||||||
notification_free(old);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -258,24 +232,16 @@ void queues_notification_close_id(int id, enum reason reason)
|
|||||||
{
|
{
|
||||||
notification *target = NULL;
|
notification *target = NULL;
|
||||||
|
|
||||||
for (GList *iter = g_queue_peek_head_link(displayed); iter;
|
GQueue *allqueues[] = { displayed, waiting };
|
||||||
iter = iter->next) {
|
for (int i = 0; i < sizeof(allqueues)/sizeof(GList*); i++) {
|
||||||
notification *n = iter->data;
|
for (GList *iter = g_queue_peek_head_link(allqueues[i]); iter;
|
||||||
if (n->id == id) {
|
iter = iter->next) {
|
||||||
g_queue_remove(displayed, n);
|
notification *n = iter->data;
|
||||||
target = n;
|
if (n->id == id) {
|
||||||
break;
|
g_queue_remove(allqueues[i], n);
|
||||||
}
|
target = n;
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
for (GList *iter = g_queue_peek_head_link(waiting); iter;
|
|
||||||
iter = iter->next) {
|
|
||||||
notification *n = iter->data;
|
|
||||||
if (n->id == id) {
|
|
||||||
assert(target == NULL);
|
|
||||||
g_queue_remove(waiting, n);
|
|
||||||
target = n;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user