/* 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));
}
/**
*/
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)
{
}
/**
- * 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;
+ }
}