libtimezonemap/0002-Cycle-through-a-smaller-list-of-map-locations-on-rep.patch
David Shea 28bd411837 - Updated the time zone map images
- Updated the city data from geonames.org
- Fix a memory leak and potential crash with the locations list
- Cycle through a smaller list of map locations on repeated clicks
2015-05-01 13:24:40 -04:00

57 lines
2.0 KiB
Diff

From ed19e892a5f1e22d3141f81c1da04f9f91719643 Mon Sep 17 00:00:00 2001
From: David Shea <dshea@redhat.com>
Date: Tue, 24 Mar 2015 10:36:51 -0400
Subject: [PATCH 2/2] Cycle through a smaller list of map locations on repeated
clicks.
Cycling through the entire map causes erratic jumps between locations,
especially if starting in a sparsely populated area. Limit the candidate
locations to those within 50px of the mouse click, or the nearest
location if no location is within 50px.
---
src/cc-timezone-map.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/src/cc-timezone-map.c b/src/cc-timezone-map.c
index 3de453e..ed80a01 100644
--- a/src/cc-timezone-map.c
+++ b/src/cc-timezone-map.c
@@ -999,6 +999,8 @@ get_loc_for_xy (GtkWidget * widget, gint x, gint y)
location = (CcTimezoneLocation*) priv->distances->data;
} else {
+ GList *node;
+
g_list_free (priv->distances_head);
priv->distances_head = NULL;
for (i = 0; i < array->len; i++)
@@ -1016,6 +1018,25 @@ get_loc_for_xy (GtkWidget * widget, gint x, gint y)
priv->distances_head = g_list_prepend (priv->distances_head, loc);
}
priv->distances_head = g_list_sort (priv->distances_head, (GCompareFunc) sort_locations);
+
+ /* Remove locations from the list with a distance of greater than 50px,
+ * so that repeated clicks cycle through a smaller area instead of
+ * jumping all over the map. Start with the second element to ensure
+ * that at least one element stays in the list.
+ */
+ node = priv->distances_head->next;
+ while (node != NULL)
+ {
+ if (cc_timezone_location_get_dist(node->data) > (50 * 50))
+ {
+ /* Cut the list off here */
+ node->prev->next = NULL;
+ g_list_free(node);
+ }
+
+ node = g_list_next(node);
+ }
+
priv->distances = priv->distances_head;
location = (CcTimezoneLocation*) priv->distances->data;
priv->previous_x = x;
--
2.1.0