summaryrefslogtreecommitdiff
path: root/src/events.c
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2019-03-15 00:30:51 +0100
committerDaniel Carl <danielcarl@gmx.de>2019-03-15 00:40:02 +0100
commitcb7ea09517db8f0dbbfafb9851577912a42e2f9b (patch)
tree848434056adc8689a26f3af2a954328af74f0155 /src/events.c
parent2d12204d63923af143d447859a055451ff25708b (diff)
Use GSList to queue events #546.
Diffstat (limited to 'src/events.c')
-rw-r--r--src/events.c52
1 files changed, 22 insertions, 30 deletions
diff --git a/src/events.c b/src/events.c
index 29b2be9..6c6e250 100644
--- a/src/events.c
+++ b/src/events.c
@@ -5,32 +5,18 @@
/* this is only to queue GDK key events, in order to later send them if the map didn't match */
static struct {
- GdkEventKey **queue; /* queue holding submitted events */
- int qlen; /* pointer to last char in queue */
- bool processing; /* whether or not events are processing */
+ GSList *list; /* queue holding submitted events */
+ bool processing; /* whether or not events are processing */
} events = {0};
+static void process_event(GdkEventKey* event);
+
/**
* Append an event into the queue.
*/
void queue_event(GdkEventKey *e)
{
- events.queue = g_realloc(events.queue, (events.qlen + 1) * sizeof(GdkEventKey*));
-
- /* copy memory (otherwise event gets cleared by gdk) */
- events.queue[events.qlen] = gdk_event_copy(e);
- events.qlen ++;
-}
-
-void process_event(GdkEventKey* event)
-{
- if (!event) {
- return;
- }
-
- events.processing = TRUE; /* signal not to queue other events */
- gtk_main_do_event((GdkEvent*)event);
- events.processing = FALSE;
+ events.list = g_slist_append(events.list, gdk_event_copy((GdkEvent*)e));
}
/**
@@ -38,18 +24,16 @@ void process_event(GdkEventKey* event)
*/
void process_events(void)
{
- for (int i = 0; i < events.qlen; ++i) {
- process_event(events.queue[i]);
- gdk_event_free(events.queue[i]);
+ for (GSList *l = events.list; l != NULL; l = l->next) {
+ process_event((GdkEventKey*)l->data);
/* TODO take into account qk mapped key? */
}
-
- events.qlen = 0;
+ free_events();
}
/**
* Check if the events are currently processing (i.e. being sent to GDK
- * unhandled). Provided in order to encapsulate the "events" global struct.
+ * unhandled).
*/
gboolean is_processing_events(void)
{
@@ -57,14 +41,22 @@ gboolean is_processing_events(void)
}
/**
- * Clear the event queue by resetting the length. Provided in order to
- * encapsulate the "events" global struct.
+ * Clear the events list and free the allocated memory.
*/
void free_events(void)
{
- for (int i = 0; i < events.qlen; ++i) {
- gdk_event_free(events.queue[i]);
+ if (events.list) {
+ g_slist_free_full(events.list, (GDestroyNotify)gdk_event_free);
+ events.list = NULL;
}
+}
- events.qlen = 0;
+static void process_event(GdkEventKey* event)
+{
+ if (event) {
+ /* signal not to queue other events */
+ events.processing = TRUE;
+ gtk_main_do_event((GdkEvent*)event);
+ events.processing = FALSE;
+ }
}