[gtk/wip/baedert/stb-rect-pack: 1/6] GdkDisplay: Use a GQueue for the events queue
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/stb-rect-pack: 1/6] GdkDisplay: Use a GQueue for the events queue
- Date: Sun, 10 Feb 2019 09:33:40 +0000 (UTC)
commit 7b8c861471f3767ac3e78ef55bd8afea22d99cb1
Author: Timm Bäder <mail baedert org>
Date: Tue Feb 5 16:05:06 2019 +0100
GdkDisplay: Use a GQueue for the events queue
gdk/gdkdisplay.c | 6 ++---
gdk/gdkdisplayprivate.h | 3 +--
gdk/gdkevents.c | 61 ++++++++++++++++---------------------------------
gdk/gdkinternals.h | 4 ++--
4 files changed, 26 insertions(+), 48 deletions(-)
---
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index ec8df56bd9..81e9d8aff8 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -363,6 +363,8 @@ gdk_display_init (GdkDisplay *display)
display->pointers_info = g_hash_table_new_full (NULL, NULL, NULL,
(GDestroyNotify) free_pointer_info);
+ g_queue_init (&display->queued_events);
+
display->debug_flags = _gdk_debug_flags;
display->composited = TRUE;
@@ -376,9 +378,7 @@ gdk_display_dispose (GObject *object)
_gdk_display_manager_remove_display (gdk_display_manager_get (), display);
- g_list_free_full (display->queued_events, (GDestroyNotify) g_object_unref);
- display->queued_events = NULL;
- display->queued_tail = NULL;
+ g_queue_clear (&display->queued_events);
G_OBJECT_CLASS (gdk_display_parent_class)->dispose (object);
}
diff --git a/gdk/gdkdisplayprivate.h b/gdk/gdkdisplayprivate.h
index 12bdd4ecd1..986a18b575 100644
--- a/gdk/gdkdisplayprivate.h
+++ b/gdk/gdkdisplayprivate.h
@@ -74,8 +74,7 @@ struct _GdkDisplay
{
GObject parent_instance;
- GList *queued_events;
- GList *queued_tail;
+ GQueue queued_events;
guint event_pause_count; /* How many times events are blocked */
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index 052eaca640..bbdf0305ed 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -185,7 +185,7 @@ _gdk_event_queue_find_first (GdkDisplay *display)
gboolean paused = display->event_pause_count > 0;
- tmp_list = display->queued_events;
+ tmp_list = g_queue_peek_head_link (&display->queued_events);
while (tmp_list)
{
GdkEvent *event = tmp_list->data;
@@ -221,14 +221,9 @@ GList *
_gdk_event_queue_append (GdkDisplay *display,
GdkEvent *event)
{
- display->queued_tail = g_list_append (display->queued_tail, event);
-
- if (!display->queued_events)
- display->queued_events = display->queued_tail;
- else
- display->queued_tail = display->queued_tail->next;
+ g_queue_push_tail (&display->queued_events, event);
- return display->queued_tail;
+ return g_queue_peek_tail_link (&display->queued_events);
}
/**
@@ -239,22 +234,18 @@ _gdk_event_queue_append (GdkDisplay *display,
*
* Appends an event after the specified event, or if it isn’t in
* the queue, onto the tail of the event queue.
- *
- * Returns: the newly appended list node.
*/
-GList*
+void
_gdk_event_queue_insert_after (GdkDisplay *display,
GdkEvent *sibling,
GdkEvent *event)
{
- GList *prev = g_list_find (display->queued_events, sibling);
- if (prev && prev->next)
- {
- display->queued_events = g_list_insert_before (display->queued_events, prev->next, event);
- return prev->next;
- }
+ GList *prev = g_queue_find (&display->queued_events, sibling);
+
+ if (prev)
+ g_queue_insert_after (&display->queued_events, prev, event);
else
- return _gdk_event_queue_append (display, event);
+ g_queue_push_tail (&display->queued_events, event);
}
/**
@@ -268,19 +259,17 @@ _gdk_event_queue_insert_after (GdkDisplay *display,
*
* Returns: the newly prepended list node.
*/
-GList*
+void
_gdk_event_queue_insert_before (GdkDisplay *display,
GdkEvent *sibling,
GdkEvent *event)
{
- GList *next = g_list_find (display->queued_events, sibling);
+ GList *next = g_queue_find (&display->queued_events, sibling);
+
if (next)
- {
- display->queued_events = g_list_insert_before (display->queued_events, next, event);
- return next->prev;
- }
+ g_queue_insert_before (&display->queued_events, next, event);
else
- return _gdk_event_queue_append (display, event);
+ g_queue_push_head (&display->queued_events, event);
}
@@ -295,15 +284,7 @@ void
_gdk_event_queue_remove_link (GdkDisplay *display,
GList *node)
{
- if (node->prev)
- node->prev->next = node->next;
- else
- display->queued_events = node->next;
-
- if (node->next)
- node->next->prev = node->prev;
- else
- display->queued_tail = node->prev;
+ g_queue_unlink (&display->queued_events, node);
}
/**
@@ -368,7 +349,7 @@ _gdk_event_queue_handle_motion_compression (GdkDisplay *display)
/* If the last N events in the event queue are motion notify
* events for the same surface, drop all but the last */
- tmp_list = display->queued_tail;
+ tmp_list = g_queue_peek_tail_link (&display->queued_events);
while (tmp_list)
{
@@ -409,14 +390,12 @@ _gdk_event_queue_handle_motion_compression (GdkDisplay *display)
gdk_event_push_history (last_motion, pending_motions->data);
g_object_unref (pending_motions->data);
- display->queued_events = g_list_delete_link (display->queued_events,
- pending_motions);
+ g_queue_delete_link (&display->queued_events, pending_motions);
pending_motions = next;
}
- if (pending_motions &&
- pending_motions == display->queued_events &&
- pending_motions == display->queued_tail)
+ if (g_queue_get_length (&display->queued_events) == 1 &&
+ g_queue_peek_head_link (&display->queued_events) == pending_motions)
{
GdkFrameClock *clock = gdk_surface_get_frame_clock (pending_motion_surface);
if (clock) /* might be NULL if surface was destroyed */
@@ -429,7 +408,7 @@ _gdk_event_queue_flush (GdkDisplay *display)
{
GList *tmp_list;
- for (tmp_list = display->queued_events; tmp_list; tmp_list = tmp_list->next)
+ for (tmp_list = display->queued_events.head; tmp_list; tmp_list = tmp_list->next)
{
GdkEvent *event = tmp_list->data;
event->any.flags |= GDK_EVENT_FLUSHED;
diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h
index a8c4bb6176..30429e931a 100644
--- a/gdk/gdkinternals.h
+++ b/gdk/gdkinternals.h
@@ -233,10 +233,10 @@ void _gdk_event_queue_remove_link (GdkDisplay *display,
GList *node);
GList* _gdk_event_queue_append (GdkDisplay *display,
GdkEvent *event);
-GList* _gdk_event_queue_insert_after (GdkDisplay *display,
+void _gdk_event_queue_insert_after (GdkDisplay *display,
GdkEvent *after_event,
GdkEvent *event);
-GList* _gdk_event_queue_insert_before(GdkDisplay *display,
+void _gdk_event_queue_insert_before(GdkDisplay *display,
GdkEvent *after_event,
GdkEvent *event);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]