diff options
author | Mattias Andrée <m@maandree.se> | 2025-03-25 23:06:51 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2025-03-25 23:06:51 +0100 |
commit | 8fed0248b8c26a4135bd230ec9dea84c4ee23233 (patch) | |
tree | 098b52dd860a015a25b4b91e03e14ea3b31cbb30 | |
parent | Remove pointless inclusion guard (diff) | |
download | redshift-ng-8fed0248b8c26a4135bd230ec9dea84c4ee23233.tar.gz redshift-ng-8fed0248b8c26a4135bd230ec9dea84c4ee23233.tar.bz2 redshift-ng-8fed0248b8c26a4135bd230ec9dea84c4ee23233.tar.xz |
Add support for /etc/geolocation and guessing by timezone
Signed-off-by: Mattias Andrée <m@maandree.se>
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/common.h | 5 | ||||
-rw-r--r-- | src/config.mk | 4 | ||||
-rw-r--r-- | src/location-corelocation.m | 2 | ||||
-rw-r--r-- | src/location-geoclue2.c | 2 | ||||
-rw-r--r-- | src/location-geofile.c | 114 | ||||
-rw-r--r-- | src/location-manual.c | 2 | ||||
-rw-r--r-- | src/location-timezone.c | 108 | ||||
-rw-r--r-- | src/location.c | 4 |
10 files changed, 240 insertions, 7 deletions
@@ -13,8 +13,6 @@ https://github.com/jonls/redshift/pull/782 Update AppStream metadata for redshif https://github.com/jonls/redshift/pull/788 redshift-gtk-desktop.in: Remove StartupNotify. https://github.com/jonls/redshift/pull/864 Fix apparmor config. -https://github.com/jonls/redshift/issues/36 Fallback location provider -https://github.com/jonls/redshift/issues/150 Startup crash if no working DNS https://github.com/jonls/redshift/issues/154 Configurable duration between gamma adjustments https://github.com/jonls/redshift/issues/155 Redshift 1.10 - Clicking Icon Off - Screen Doesn't Return Full Brightness https://github.com/jonls/redshift/issues/170 Can't see right icons in Linux Mint 17 Cinnamon @@ -104,3 +102,5 @@ Add signals for setting location Add signals for responding with sigqueue the state of redshift print, for use by frontends, what mode redshift was started in [Windows] Make sure extended paths are supported +Document the "geofile" location provider +Document the "timezone" location provider diff --git a/src/Makefile b/src/Makefile index a62a0cf..417d001 100644 --- a/src/Makefile +++ b/src/Makefile @@ -24,6 +24,8 @@ OBJ =\ location.o\ location-geoclue2.o\ location-manual.o\ + location-geofile.o\ + location-timezone.o\ redshift.o\ signals.o\ util.o diff --git a/src/common.h b/src/common.h index f1bd414..d9a268d 100644 --- a/src/common.h +++ b/src/common.h @@ -60,6 +60,7 @@ #endif #include <libgamma.h> +#include <libgeome.h> #include <libred.h> @@ -1669,6 +1670,10 @@ extern const struct location_provider geoclue2_location_provider; #ifdef ENABLE_CORELOCATION extern const struct location_provider corelocation_location_provider; #endif +#ifndef WINDOWS +extern const struct location_provider geofile_location_provider; +extern const struct location_provider timezone_location_provider; +#endif #if defined(__GNUC__) diff --git a/src/config.mk b/src/config.mk index d8e2a19..00a032c 100644 --- a/src/config.mk +++ b/src/config.mk @@ -12,9 +12,9 @@ PKGCONFIG_LDFLAGS = $(PKGCONFIG) --libs GEOCLUE_LIBS = glib-2.0 gio-2.0 -LIBS_PKGCONFIG = $(DRM_LIBS) $(GEOCLUE_LIBS) libgamma +LIBS_PKGCONFIG = $(GEOCLUE_LIBS) libgamma CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_GNU_SOURCE\ -DENABLE_GEOCLUE2 -DENABLE_COOPGAMMA CFLAGS = $$($(PKGCONFIG_CFLAGS) $(LIBS_PKGCONFIG)) -LDFLAGS = $$($(PKGCONFIG_LDFLAGS) $(LIBS_PKGCONFIG)) -lm -lcoopgamma -lred +LDFLAGS = $$($(PKGCONFIG_LDFLAGS) $(LIBS_PKGCONFIG)) -lm -lcoopgamma -lred -lgeome diff --git a/src/location-corelocation.m b/src/location-corelocation.m index 035dda7..1b94137 100644 --- a/src/location-corelocation.m +++ b/src/location-corelocation.m @@ -268,7 +268,7 @@ corelocation_set_option(struct location_state *state, const char *key, const cha { (void) state; (void) value; - weprintf(_("Unknown method parameter: `%s'."), key); + weprintf(_("Unknown provider parameter: `%s'."), key); return -1; } diff --git a/src/location-geoclue2.c b/src/location-geoclue2.c index 199db2d..9eb49fe 100644 --- a/src/location-geoclue2.c +++ b/src/location-geoclue2.c @@ -408,7 +408,7 @@ geoclue2_set_option(struct location_state *state, const char *key, const char *v { (void) state; (void) value; - weprintf(_("Unknown method parameter: `%s'."), key); + weprintf(_("Unknown provider parameter: `%s'."), key); return -1; } diff --git a/src/location-geofile.c b/src/location-geofile.c new file mode 100644 index 0000000..62d6b26 --- /dev/null +++ b/src/location-geofile.c @@ -0,0 +1,114 @@ +/*- + * redshift-ng - Automatically adjust display colour temperature according the Sun + * + * Copyright (c) 2009-2018 Jon Lund Steffensen <jonlst@gmail.com> + * Copyright (c) 2014-2016, 2025 Mattias Andrée <m@maandree.se> + * + * redshift-ng is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * redshift-ng is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with redshift-ng. If not, see <http://www.gnu.org/licenses/>. + */ +#include "common.h" + + +struct location_state { + /** + * The loaded location + */ + struct location location; + + /** + * File to read location from, `NULL` for default + */ + char *file; +}; + + +static int +geofile_create(struct location_state **state_out) +{ + *state_out = emalloc(sizeof(**state_out)); + (*state_out)->file = NULL; + return 0; +} + + +GCC_ONLY(__attribute__((__pure__))) +static int +geofile_start(struct location_state *state) +{ + struct libgeome_data data = {.requested_data = LIBGEOME_DATUM_LATITUDE | LIBGEOME_DATUM_LONGITUDE}; + struct libgeome_context ctx; + int r; + libgeome_basic_context(&ctx, argv0); + r = libgeome_get_from_file(&ctx, &data, state->file); + free(state->file); + state->file = NULL; + if (r || data.requested_data != (LIBGEOME_DATUM_LATITUDE | LIBGEOME_DATUM_LONGITUDE)) + return -1; + state->location.latitude = data.latitude; + state->location.longitude = data.longitude; + return 0; +} + + +static void +geofile_free(struct location_state *state) +{ + free(state->file); + free(state); +} + + +static void +geofile_print_help(void) +{ + printf(_("Specify location via file.\n")); + printf("\n"); + + printf(" file=%s %s\n", _("FILE "), _("File to read location from (empty for default)")); + printf("\n"); +} + + +static int +geofile_set_option(struct location_state *state, const char *key, const char *value) +{ + if (!strcasecmp(key, "file")) { + free(state->file); + state->file = *value ? estrdup(value) : NULL; + return 0; + } else { + weprintf(_("Unknown provider parameter: `%s'."), key); + return -1; + } +} + + +static int +geofile_get_fd(struct location_state *state) +{ + (void) state; + return -1; +} + + +static int +geofile_fetch(struct location_state *state, struct location *location_out, int *available_out) +{ + *location_out = state->location; + *available_out = 1; + return 0; +} + + +const struct location_provider geofile_location_provider = LOCATION_PROVIDER_INIT("geofile", geofile); diff --git a/src/location-manual.c b/src/location-manual.c index c6c679e..2928f37 100644 --- a/src/location-manual.c +++ b/src/location-manual.c @@ -90,7 +90,7 @@ manual_set_option(struct location_state *state, const char *key, const char *val } else if (!strcasecmp(key, "lon")) { state->location.longitude = v; } else { - weprintf(_("Unknown method parameter: `%s'."), key); + weprintf(_("Unknown provider parameter: `%s'."), key); return -1; } diff --git a/src/location-timezone.c b/src/location-timezone.c new file mode 100644 index 0000000..58bf0cf --- /dev/null +++ b/src/location-timezone.c @@ -0,0 +1,108 @@ +/*- + * redshift-ng - Automatically adjust display colour temperature according the Sun + * + * Copyright (c) 2009-2018 Jon Lund Steffensen <jonlst@gmail.com> + * Copyright (c) 2014-2016, 2025 Mattias Andrée <m@maandree.se> + * + * redshift-ng is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * redshift-ng is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with redshift-ng. If not, see <http://www.gnu.org/licenses/>. + */ +#include "common.h" + + +struct location_state { + /** + * The loaded location + */ + struct location location; +}; + + +static int +timezone_create(struct location_state **state_out) +{ + *state_out = emalloc(sizeof(**state_out)); + return 0; +} + + +GCC_ONLY(__attribute__((__pure__))) +static int +timezone_start(struct location_state *state) +{ + struct libgeome_data data; + struct libgeome_context ctx; + int r; + libgeome_basic_context(&ctx, argv0); + + data.requested_data = LIBGEOME_DATUM_LATITUDE | LIBGEOME_DATUM_LONGITUDE; + r = libgeome_get_from_timezone(&ctx, &data); + if (r) { + data.requested_data = LIBGEOME_DATUM_LATITUDE | LIBGEOME_DATUM_LONGITUDE; + r = libgeome_get_from_time(&ctx, &data); + } + + if (r || !(data.requested_data & LIBGEOME_DATUM_LONGITUDE)) + return -1; + if (data.requested_data & LIBGEOME_DATUM_LATITUDE) + state->location.latitude = data.latitude; + else + state->location.latitude = 0; + state->location.longitude = data.longitude; + return 0; +} + + +static void +timezone_free(struct location_state *state) +{ + free(state); +} + + +static void +timezone_print_help(void) +{ + printf(_("Get rough location from timezone.\n")); + printf("\n"); +} + + +static int +timezone_set_option(struct location_state *state, const char *key, const char *value) +{ + (void) state; + (void) value; + weprintf(_("Unknown provider parameter: `%s'."), key); + return -1; +} + + +static int +timezone_get_fd(struct location_state *state) +{ + (void) state; + return -1; +} + + +static int +timezone_fetch(struct location_state *state, struct location *location_out, int *available_out) +{ + *location_out = state->location; + *available_out = 1; + return 0; +} + + +const struct location_provider timezone_location_provider = LOCATION_PROVIDER_INIT("timezone", timezone); diff --git a/src/location.c b/src/location.c index 8ca4374..5979a2d 100644 --- a/src/location.c +++ b/src/location.c @@ -28,6 +28,10 @@ const struct location_provider *location_providers[] = { &corelocation_location_provider, #endif &manual_location_provider, +#ifndef WINDOWS + &geofile_location_provider, + &timezone_location_provider, +#endif NULL }; |