diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2014-12-31 00:11:24 -0500 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2015-01-04 16:32:47 -0500 |
commit | 799b08214dffc3c86e30c4547acd9015078a18ac (patch) | |
tree | fd01ab4421eee6bff66495431de5fb00b047245b | |
parent | Merge changes from 1.10 release branch (diff) | |
download | redshift-ng-799b08214dffc3c86e30c4547acd9015078a18ac.tar.gz redshift-ng-799b08214dffc3c86e30c4547acd9015078a18ac.tar.bz2 redshift-ng-799b08214dffc3c86e30c4547acd9015078a18ac.tar.xz |
Add location_t type with lat/lon fields
-rw-r--r-- | src/location-corelocation.h | 4 | ||||
-rw-r--r-- | src/location-corelocation.m | 7 | ||||
-rw-r--r-- | src/location-geoclue.c | 7 | ||||
-rw-r--r-- | src/location-geoclue.h | 4 | ||||
-rw-r--r-- | src/location-geoclue2.c | 13 | ||||
-rw-r--r-- | src/location-geoclue2.h | 4 | ||||
-rw-r--r-- | src/location-manual.c | 19 | ||||
-rw-r--r-- | src/location-manual.h | 11 | ||||
-rw-r--r-- | src/redshift.c | 20 | ||||
-rw-r--r-- | src/redshift.h | 10 |
10 files changed, 56 insertions, 43 deletions
diff --git a/src/location-corelocation.h b/src/location-corelocation.h index 58dddd7..4b74382 100644 --- a/src/location-corelocation.h +++ b/src/location-corelocation.h @@ -22,6 +22,8 @@ #include <stdio.h> +#include "redshift.h" + int location_corelocation_init(void *state); int location_corelocation_start(void *state); @@ -32,7 +34,7 @@ int location_corelocation_set_option(void *state, const char *key, const char *value); int location_corelocation_get_location(void *state, - float *lat, float *lon); + location_t *location); #endif /* ! REDSHIFT_LOCATION_CORELOCATION_H */ diff --git a/src/location-corelocation.m b/src/location-corelocation.m index edf3e45..2f1768d 100644 --- a/src/location-corelocation.m +++ b/src/location-corelocation.m @@ -25,6 +25,7 @@ #import <CoreLocation/CoreLocation.h> #include "location-corelocation.h" +#include "redshift.h" #include <stdio.h> @@ -143,7 +144,7 @@ location_corelocation_set_option(void *state, int location_corelocation_get_location(void *state, - float *lat, float *lon) + location_t *location) { int result = -1; @@ -153,8 +154,8 @@ location_corelocation_get_location(void *state, CFRunLoopRun(); if (delegate.success) { - *lat = delegate.latitude; - *lon = delegate.longitude; + location->lat = delegate.latitude; + location->lon = delegate.longitude; result = 0; } } diff --git a/src/location-geoclue.c b/src/location-geoclue.c index 378b933..b2616bf 100644 --- a/src/location-geoclue.c +++ b/src/location-geoclue.c @@ -28,6 +28,7 @@ #include <glib-object.h> #include "location-geoclue.h" +#include "redshift.h" #ifdef ENABLE_NLS # include <libintl.h> @@ -185,7 +186,7 @@ location_geoclue_set_option(location_geoclue_state_t *state, int location_geoclue_get_location(location_geoclue_state_t *state, - float *lat, float *lon) + location_t *location) { GeocluePositionFields fields; GError *error = NULL; @@ -210,8 +211,8 @@ location_geoclue_get_location(location_geoclue_state_t *state, return -1; } - *lat = latitude; - *lon = longitude; + location->lat = latitude; + location->lon = longitude; return 0; } diff --git a/src/location-geoclue.h b/src/location-geoclue.h index 54a527b..3847ee2 100644 --- a/src/location-geoclue.h +++ b/src/location-geoclue.h @@ -23,6 +23,8 @@ #include <stdio.h> #include <geoclue/geoclue-position.h> +#include "redshift.h" + typedef struct { GeocluePosition *position; /* main geoclue object */ char *provider; /* name of a geoclue provider */ @@ -38,7 +40,7 @@ int location_geoclue_set_option(location_geoclue_state_t *state, const char *key, const char *value); int location_geoclue_get_location(location_geoclue_state_t *state, - float *lat, float *lon); + location_t *loc); #endif /* ! REDSHIFT_LOCATION_GEOCLUE_H */ diff --git a/src/location-geoclue2.c b/src/location-geoclue2.c index b559196..abccbd3 100644 --- a/src/location-geoclue2.c +++ b/src/location-geoclue2.c @@ -25,6 +25,7 @@ #include <gio/gio.h> #include "location-geoclue2.h" +#include "redshift.h" #ifdef ENABLE_NLS # include <libintl.h> @@ -38,8 +39,7 @@ typedef struct { GMainLoop *loop; int available; - float latitude; - float longitude; + location_t location; } get_location_data_t; @@ -120,11 +120,11 @@ geoclue_client_signal_cb(GDBusProxy *client, gchar *sender_name, /* Read location properties */ GVariant *lat_v = g_dbus_proxy_get_cached_property(location, "Latitude"); - data->latitude = g_variant_get_double(lat_v); + data->location.lat = g_variant_get_double(lat_v); GVariant *lon_v = g_dbus_proxy_get_cached_property(location, "Longitude"); - data->longitude = g_variant_get_double(lon_v); + data->location.lon = g_variant_get_double(lon_v); data->available = 1; @@ -273,7 +273,7 @@ on_name_vanished(GDBusConnection *connection, const gchar *name, int location_geoclue2_get_location(void *state, - float *lat, float *lon) + location_t *location) { get_location_data_t data; data.available = 0; @@ -291,8 +291,7 @@ location_geoclue2_get_location(void *state, if (!data.available) return -1; - *lat = data.latitude; - *lon = data.longitude; + *location = data.location; return 0; } diff --git a/src/location-geoclue2.h b/src/location-geoclue2.h index f0553e4..c3c377b 100644 --- a/src/location-geoclue2.h +++ b/src/location-geoclue2.h @@ -22,6 +22,8 @@ #include <stdio.h> +#include "redshift.h" + int location_geoclue2_init(void *state); int location_geoclue2_start(void *state); @@ -32,7 +34,7 @@ int location_geoclue2_set_option(void *state, const char *key, const char *value); int location_geoclue2_get_location(void *state, - float *lat, float *lon); + location_t *loc); #endif /* ! REDSHIFT_LOCATION_GEOCLUE2_H */ diff --git a/src/location-manual.c b/src/location-manual.c index 30dfc9c..c5da074 100644 --- a/src/location-manual.c +++ b/src/location-manual.c @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com> */ #include <stdio.h> @@ -36,8 +36,8 @@ int location_manual_init(location_manual_state_t *state) { - state->lat = NAN; - state->lon = NAN; + state->loc.lat = NAN; + state->loc.lon = NAN; return 0; } @@ -46,7 +46,7 @@ int location_manual_start(location_manual_state_t *state) { /* Latitude and longitude must be set */ - if (isnan(state->lat) || isnan(state->lon)) { + if (isnan(state->loc.lat) || isnan(state->loc.lon)) { fputs(_("Latitude and longitude must be set.\n"), stderr); exit(EXIT_FAILURE); } @@ -89,9 +89,9 @@ location_manual_set_option(location_manual_state_t *state, const char *key, } if (strcasecmp(key, "lat") == 0) { - state->lat = v; + state->loc.lat = v; } else if (strcasecmp(key, "lon") == 0) { - state->lon = v; + state->loc.lon = v; } else { fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key); return -1; @@ -101,11 +101,10 @@ location_manual_set_option(location_manual_state_t *state, const char *key, } int -location_manual_get_location(location_manual_state_t *state, float *lat, - float *lon) +location_manual_get_location(location_manual_state_t *state, + location_t *loc) { - *lat = state->lat; - *lon = state->lon; + *loc = state->loc; return 0; } diff --git a/src/location-manual.h b/src/location-manual.h index 389294d..e70d9cf 100644 --- a/src/location-manual.h +++ b/src/location-manual.h @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com> */ #ifndef REDSHIFT_LOCATION_MANUAL_H @@ -22,10 +22,11 @@ #include <stdio.h> +#include "redshift.h" + typedef struct { - float lat; - float lon; + location_t loc; } location_manual_state_t; @@ -37,8 +38,8 @@ void location_manual_print_help(FILE *f); int location_manual_set_option(location_manual_state_t *state, const char *key, const char *value); -int location_manual_get_location(location_manual_state_t *state, float *lat, - float *lon); +int location_manual_get_location(location_manual_state_t *state, + location_t *loc); #endif /* ! REDSHIFT_LOCATION_MANUAL_H */ diff --git a/src/redshift.c b/src/redshift.c index 4fa9b85..3d22064 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -1119,8 +1119,7 @@ main(int argc, char *argv[]) if (transition < 0) transition = 1; - float lat = NAN; - float lon = NAN; + location_t loc = { NAN, NAN }; /* Initialize location provider. If provider is NULL try all providers until one that works is found. */ @@ -1167,7 +1166,7 @@ main(int argc, char *argv[]) } /* Get current location. */ - r = provider->get_location(&location_state, &lat, &lon); + r = provider->get_location(&location_state, &loc); if (r < 0) { fputs(_("Unable to get location from provider.\n"), stderr); @@ -1190,8 +1189,10 @@ main(int argc, char *argv[]) The string following each number is an abreviation for north, source, east or west (N, S, E, W). */ printf(_("Location: %.2f %s, %.2f %s\n"), - fabs(lat), lat >= 0.f ? north : south, - fabs(lon), lon >= 0.f ? east : west); + fabs(loc.lat), + loc.lat >= 0.f ? north : south, + fabs(loc.lon), + loc.lon >= 0.f ? east : west); printf(_("Temperatures: %dK at day, %dK at night\n"), day.temperature, night.temperature); @@ -1202,7 +1203,7 @@ main(int argc, char *argv[]) } /* Latitude */ - if (lat < MIN_LAT || lat > MAX_LAT) { + if (loc.lat < MIN_LAT || loc.lat > MAX_LAT) { /* TRANSLATORS: Append degree symbols if possible. */ fprintf(stderr, _("Latitude must be between %.1f and %.1f.\n"), @@ -1211,7 +1212,7 @@ main(int argc, char *argv[]) } /* Longitude */ - if (lon < MIN_LON || lon > MAX_LON) { + if (loc.lon < MIN_LON || loc.lon > MAX_LON) { /* TRANSLATORS: Append degree symbols if possible. */ fprintf(stderr, _("Longitude must be between" @@ -1339,7 +1340,7 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } - double elevation = solar_elevation(now, lat, lon); + double elevation = solar_elevation(now, loc.lat, loc.lon); if (verbose) { /* TRANSLATORS: Append degree symbol if possible. */ @@ -1555,7 +1556,8 @@ main(int argc, char *argv[]) } /* Current angular elevation of the sun */ - double elevation = solar_elevation(now, lat, lon); + double elevation = + solar_elevation(now, loc.lat, loc.lon); /* Use elevation of sun to set color temperature */ color_setting_t interp; diff --git a/src/redshift.h b/src/redshift.h index 5f4335c..bac8e34 100644 --- a/src/redshift.h +++ b/src/redshift.h @@ -24,6 +24,12 @@ #include <stdlib.h> +/* Location */ +typedef struct { + float lat; + float lon; +} location_t; + /* Periods of day. */ typedef enum { PERIOD_NONE = 0, @@ -32,7 +38,6 @@ typedef enum { PERIOD_TRANSITION } period_t; - /* Color setting */ typedef struct { int temperature; @@ -84,8 +89,7 @@ typedef void location_provider_free_func(void *state); typedef void location_provider_print_help_func(FILE *f); typedef int location_provider_set_option_func(void *state, const char *key, const char *value); -typedef int location_provider_get_location_func(void *state, float *lat, - float *lon); +typedef int location_provider_get_location_func(void *state, location_t *loc); typedef struct { char *name; |