From: Michael Mackus Date: Tue, 1 Nov 2016 22:13:08 +0000 (-0700) Subject: Process events through GDK X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=bd0ddfebef704f4e82928b11deef0782b285a8d2;p=vimb.git Process events through GDK --- diff --git a/src/events.c b/src/events.c index a683938..92debb7 100644 --- a/src/events.c +++ b/src/events.c @@ -17,12 +17,25 @@ void queue_event(GdkEventKey* e) return; } - if (events.queue == NULL) { - events.queue = malloc(0); + GdkEventKey **newqueue = realloc(events.queue, (events.qlen + 1) * sizeof **newqueue); + + if (newqueue == NULL) { + // error allocating memory + return; } - events.queue = realloc(events.queue, (events.qlen + 1) * sizeof *events.queue); - events.queue[events.qlen] = e; + events.queue = newqueue; + + /* copy memory (otherwise event gets cleared by gdk) */ + GdkEventKey* tmp = malloc(sizeof *tmp); + memcpy(tmp, e, sizeof *e); + + if (tmp == NULL) { + // error allocating memory + return; + } + + events.queue[events.qlen] = tmp; events.qlen ++; } @@ -40,7 +53,9 @@ void process_events() for (int i = 0; i < events.qlen; ++i) { - // TODO send to gdk + GdkEventKey* event = events.queue[i]; + gtk_main_do_event ((GdkEvent*) event); + gdk_event_free ((GdkEvent*) event); } events.qlen = 0; @@ -62,5 +77,11 @@ bool is_processing_events() */ void clear_events() { + for (int i = 0; i < events.qlen; ++i) + { + GdkEventKey* event = events.queue[events.qlen]; + gdk_event_free ((GdkEvent*) event); + } + events.qlen = 0; }