From: Michael Stapelberg Date: Wed, 11 Mar 2009 19:06:30 +0000 (+0100) Subject: Implement cleaning up the list of ignored events X-Git-Tag: 3.a~31 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=17bcdd8b0fc7ead641839db9ea9fa822d6ebcabe;p=i3%2Fi3 Implement cleaning up the list of ignored events --- diff --git a/src/handlers.c b/src/handlers.c index e80ae8ac..0a7b520b 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -35,7 +35,7 @@ /* After mapping/unmapping windows, a notify event is generated. However, we don’t want it, since it’d trigger an infinite loop of switching between the different windows when changing workspaces */ -SLIST_HEAD(ignore_head, Ignore_Event) ignore_events; +static SLIST_HEAD(ignore_head, Ignore_Event) ignore_events; static void add_ignore_event(const int sequence) { struct Ignore_Event *event = smalloc(sizeof(struct Ignore_Event)); @@ -54,7 +54,17 @@ static void add_ignore_event(const int sequence) { */ static bool event_is_ignored(const int sequence) { struct Ignore_Event *event; - /* TODO: cleanup this list */ + time_t now = time(NULL); + for (event = SLIST_FIRST(&ignore_events); event != SLIST_END(&ignore_events);) { + if ((now - event->added) > 5) { + LOG("Entry is older than five seconds, cleaning up\n"); + struct Ignore_Event *save = event; + event = SLIST_NEXT(event, ignore_events); + SLIST_REMOVE(&ignore_events, save, Ignore_Event, ignore_events); + free(save); + } else event = SLIST_NEXT(event, ignore_events); + } + SLIST_FOREACH(event, &ignore_events, ignore_events) { if (event->sequence == sequence) { LOG("Ignoring event (sequence %d)\n", sequence);