From: Daniel Carl Date: Thu, 14 Mar 2019 23:38:20 +0000 (+0100) Subject: Move functions from events.c to map.c #546. X-Git-Url: https://git.owens.tech/git.owens.tech/git.owens.tech/git?a=commitdiff_plain;h=beba6b162c7a199f871061dac217ef6c88b1a598;p=vimb.git Move functions from events.c to map.c #546. --- diff --git a/src/events.c b/src/events.c deleted file mode 100644 index 6c6e250..0000000 --- a/src/events.c +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright (C) 2016-2019 Michael Mackus */ -#include - -#include "events.h" - -/* this is only to queue GDK key events, in order to later send them if the map didn't match */ -static struct { - 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.list = g_slist_append(events.list, gdk_event_copy((GdkEvent*)e)); -} - -/** - * Process events in the queue, sending the key events to GDK. - */ -void process_events(void) -{ - for (GSList *l = events.list; l != NULL; l = l->next) { - process_event((GdkEventKey*)l->data); - /* TODO take into account qk mapped key? */ - } - free_events(); -} - -/** - * Check if the events are currently processing (i.e. being sent to GDK - * unhandled). - */ -gboolean is_processing_events(void) -{ - return events.processing; -} - -/** - * Clear the events list and free the allocated memory. - */ -void free_events(void) -{ - if (events.list) { - g_slist_free_full(events.list, (GDestroyNotify)gdk_event_free); - events.list = NULL; - } -} - -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; - } -} diff --git a/src/events.h b/src/events.h deleted file mode 100644 index 75e335b..0000000 --- a/src/events.h +++ /dev/null @@ -1,15 +0,0 @@ -/* Copyright (C) 2016-2019 Michael Mackus */ -#ifndef _EVENTS_H -#define _EVENTS_H - -#include -#include -#include "main.h" -#include "map.h" - -void queue_event(GdkEventKey *e); -void process_events(void); -gboolean is_processing_events(void); -void free_events(void); - -#endif /* end of include guard: _MAP_H */ diff --git a/src/map.c b/src/map.c index 7e323be..4621fa6 100644 --- a/src/map.c +++ b/src/map.c @@ -23,7 +23,6 @@ #include "ascii.h" #include "config.h" -#include "events.h" #include "main.h" #include "map.h" #include "util.h" @@ -37,6 +36,10 @@ static gboolean map_delete_by_lhs(Client *c, const char *lhs, int len, char mode static void showcmd(Client *c, int ch); static char *transchar(int c); static int utf_char2bytes(guint c, guchar *buf); +static void queue_event(GdkEventKey *e); +static void process_events(void); +static void free_events(void); +static void process_event(GdkEventKey* event); extern struct Vimb vb; @@ -98,6 +101,12 @@ static struct { {"", 5, CSI_STR "F2", 3}, }; +/* this is only to queue GDK key events, in order to later send them if the map didn't match */ +static struct { + GSList *list; /* queue holding submitted events */ + gboolean processing; /* whether or not events are processing */ +} events = {0}; + void map_init(Client *c) { c->map.queue = g_string_sized_new(50); @@ -325,7 +334,7 @@ gboolean map_delete(Client *c, const char *in, char mode) */ gboolean on_map_keypress(GtkWidget *widget, GdkEventKey* event, Client *c) { - if (is_processing_events()) { + if (events.processing) { /* events are processing, pass all keys unmodified */ return FALSE; } @@ -679,3 +688,44 @@ static int utf_char2bytes(guint c, guchar *buf) buf[5] = 0x80 + (c & 0x3f); return 6; } + +/** + * Append an event into the queue. + */ +static void queue_event(GdkEventKey *e) +{ + events.list = g_slist_append(events.list, gdk_event_copy((GdkEvent*)e)); +} + +/** + * Process events in the queue, sending the key events to GDK. + */ +static void process_events(void) +{ + for (GSList *l = events.list; l != NULL; l = l->next) { + process_event((GdkEventKey*)l->data); + /* TODO take into account qk mapped key? */ + } + free_events(); +} + +/** + * Clear the events list and free the allocated memory. + */ +static void free_events(void) +{ + if (events.list) { + g_slist_free_full(events.list, (GDestroyNotify)gdk_event_free); + events.list = NULL; + } +} + +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; + } +}