From b42c9662303d1a33ebe038d1895c08945cdbd40f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 5 Mar 2025 19:26:58 +0100 Subject: Cleanup and style update (avoid typedef) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/colorramp.c | 10 +-- src/common.h | 170 ++++++++++++++++++++++---------------------- src/config-ini.c | 50 ++++--------- src/config-ini.h | 26 +++---- src/config.mk | 4 +- src/gamma-coopgamma.c | 77 ++++++++------------ src/gamma-drm.c | 95 ++++++++++--------------- src/gamma-dummy.c | 40 ++++------- src/gamma-quartz.c | 65 +++++++---------- src/gamma-randr.c | 67 +++++++---------- src/gamma-vidmode.c | 56 ++++++--------- src/gamma-w32gdi.c | 55 ++++++-------- src/hooks.c | 12 +--- src/location-corelocation.m | 41 ++++------- src/location-geoclue2.c | 66 +++++++---------- src/location-manual.c | 57 ++++++--------- src/options.c | 72 +++++++------------ src/options.h | 28 ++++---- src/pipeutils.c | 5 +- src/redshift.c | 148 ++++++++++++++++---------------------- src/signals.c | 3 +- src/solar.c | 4 +- src/solar.h | 4 +- src/systemtime.c | 17 +---- 24 files changed, 452 insertions(+), 720 deletions(-) (limited to 'src') diff --git a/src/colorramp.c b/src/colorramp.c index a9db111..41233d5 100644 --- a/src/colorramp.c +++ b/src/colorramp.c @@ -18,10 +18,6 @@ Copyright (c) 2013 Ingo Thies [historical, no longer applies] Copyright (c) 2016, 2025 Mattias Andrée */ - -#include -#include - #include "common.h" /* Helper macro used in the fill functions */ @@ -31,8 +27,8 @@ #define X(SUFFIX, TYPE, MAX, TRUE_MAX, DEPTH)\ void\ colorramp_fill_##SUFFIX(TYPE *gamma_r, TYPE *gamma_g, TYPE *gamma_b,\ - size_t size_r, size_t size_g, size_t size_b,\ - const color_setting_t *setting)\ + size_t size_r, size_t size_g, size_t size_b,\ + const struct color_setting *setting)\ {\ double r = 1, g = 1, b = 1;\ size_t i;\ @@ -44,5 +40,3 @@ LIST_RAMPS_STOP_VALUE_TYPES #undef X - -#undef F diff --git a/src/common.h b/src/common.h index 028865f..895fedc 100644 --- a/src/common.h +++ b/src/common.h @@ -20,139 +20,142 @@ #ifndef REDSHIFT_COMMON_H #define REDSHIFT_COMMON_H +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include -#if !defined(__WIN32__) +#include +#include +#include +#ifdef _POSIX_TIMERS +# include +#endif +#if defined(__WIN32__) || defined(_WIN32) +# include +#else +# include # include +# include +#endif + +#include + +#ifdef ENABLE_NLS +# include +#else +# define gettext(s) (s) #endif +# define _(s) gettext(s) +# define N_(s) (s) /* The color temperature when no adjustment is applied. */ #define NEUTRAL_TEMP 6500 -/* Location */ -typedef struct { - float lat; - float lon; -} location_t; - -/* Periods of day. */ -typedef enum { +enum period { PERIOD_NONE = 0, PERIOD_DAYTIME, PERIOD_NIGHT, PERIOD_TRANSITION -} period_t; +} ; -/* Color setting */ -typedef struct { - int temperature; - float gamma[3]; - float brightness; -} color_setting_t; - -/* Program modes. */ -typedef enum { +enum program_mode { PROGRAM_MODE_CONTINUAL, PROGRAM_MODE_ONE_SHOT, PROGRAM_MODE_PRINT, PROGRAM_MODE_RESET, PROGRAM_MODE_MANUAL -} program_mode_t; +}; + +struct location { + float lat, lon; +}; + +struct color_setting { + int temperature; + float gamma[3]; + float brightness; +}; /* Time range. Fields are offsets from midnight in seconds. */ -typedef struct { +struct time_range { int start; int end; -} time_range_t; +}; /* Transition scheme. The solar elevations at which the transition begins/ends, and the association color settings. */ -typedef struct { +struct transition_scheme { double high; double low; int use_time; /* When enabled, ignore elevation and use time ranges. */ - time_range_t dawn; - time_range_t dusk; - color_setting_t day; - color_setting_t night; -} transition_scheme_t; + struct time_range dawn; + struct time_range dusk; + struct color_setting day; + struct color_setting night; +}; /* Gamma adjustment method */ -typedef struct gamma_state gamma_state_t; - -typedef int gamma_method_init_func(gamma_state_t **state); -typedef int gamma_method_start_func(gamma_state_t *state, program_mode_t mode); -typedef void gamma_method_free_func(gamma_state_t *state); -typedef void gamma_method_print_help_func(FILE *f); -typedef int gamma_method_set_option_func(gamma_state_t *state, const char *key, - const char *value); -typedef void gamma_method_restore_func(gamma_state_t *state); -typedef int gamma_method_set_temperature_func( - gamma_state_t *state, const color_setting_t *setting, int preserve); - -typedef struct { +typedef struct gamma_state GAMMA_STATE; + +struct gamma_method { char *name; /* If true, this method will be tried if none is explicitly chosen. */ int autostart; /* Initialize state. Options can be set between init and start. */ - gamma_method_init_func *init; + int (*init)(GAMMA_STATE **state); /* Allocate storage and make connections that depend on options. */ - gamma_method_start_func *start; + int (*start)(GAMMA_STATE *state, enum program_mode mode); /* Free all allocated storage and close connections. */ - gamma_method_free_func *free; + void (*free)(GAMMA_STATE *state); /* Print help on options for this adjustment method. */ - gamma_method_print_help_func *print_help; + void (*print_help)(FILE *f); /* Set an option key, value-pair */ - gamma_method_set_option_func *set_option; + int (*set_option)(GAMMA_STATE *state, const char *key, const char *value); /* Restore the adjustment to the state before start was called. */ - gamma_method_restore_func *restore; + void (*restore)(GAMMA_STATE *state); /* Set a specific color temperature. */ - gamma_method_set_temperature_func *set_temperature; -} gamma_method_t; + int (*set_temperature)(GAMMA_STATE *state, const struct color_setting *setting, int preserve); +}; /* Location provider */ -typedef struct location_state location_state_t; - -typedef int location_provider_init_func(location_state_t **state); -typedef int location_provider_start_func(location_state_t *state); -typedef void location_provider_free_func(location_state_t *state); -typedef void location_provider_print_help_func(FILE *f); -typedef int location_provider_set_option_func( - location_state_t *state, const char *key, const char *value); -typedef int location_provider_get_fd_func(location_state_t *state); -typedef int location_provider_handle_func( - location_state_t *state, location_t *location, int *available); - -typedef struct { +typedef struct location_state LOCATION_STATE; + +struct location_provider { char *name; /* Initialize state. Options can be set between init and start. */ - location_provider_init_func *init; + int (*init)(LOCATION_STATE **state); /* Allocate storage and make connections that depend on options. */ - location_provider_start_func *start; + int (*start)(LOCATION_STATE *state); /* Free all allocated storage and close connections. */ - location_provider_free_func *free; + void (*free)(LOCATION_STATE *state); /* Print help on options for this location provider. */ - location_provider_print_help_func *print_help; + void (*print_help)(FILE *f); /* Set an option key, value-pair. */ - location_provider_set_option_func *set_option; + int (*set_option)(LOCATION_STATE *state, const char *key, const char *value); /* Listen and handle location updates. */ - location_provider_get_fd_func *get_fd; - location_provider_handle_func *handle; -} location_provider_t; + int (*get_fd)(LOCATION_STATE *state); + int (*handle)(LOCATION_STATE *state, struct location *location, int *available); +}; #define LIST_RAMPS_STOP_VALUE_TYPES\ @@ -165,14 +168,13 @@ typedef struct { #define X(SUFFIX, TYPE, MAX, TRUE_MAX, DEPTH)\ void colorramp_fill_##SUFFIX(TYPE *gamma_r, TYPE *gamma_g, TYPE *gamma_b,\ - size_t size_r, size_t size_g, size_t size_b,\ - const color_setting_t *setting); + size_t size_r, size_t size_g, size_t size_b,\ + const struct color_setting *setting); LIST_RAMPS_STOP_VALUE_TYPES #undef X -void hooks_signal_period_change(period_t prev_period, - period_t period); +void hooks_signal_period_change(enum period prev_period, enum period period); int pipeutils_create_nonblocking(int pipefds[2]); @@ -196,41 +198,41 @@ int systemtime_get_time(double *now); void systemtime_msleep(unsigned int msecs); -extern const gamma_method_t dummy_gamma_method; +extern const struct gamma_method dummy_gamma_method; #ifdef ENABLE_COOPGAMMA -extern const gamma_method_t coopgamma_gamma_method; +extern const struct gamma_method coopgamma_gamma_method; #endif #ifdef ENABLE_RANDR -extern const gamma_method_t randr_gamma_method; +extern const struct gamma_method randr_gamma_method; #endif #ifdef ENABLE_VIDMODE -extern const gamma_method_t vidmode_gamma_method; +extern const struct gamma_method vidmode_gamma_method; #endif #ifdef ENABLE_DRM -extern const gamma_method_t drm_gamma_method; +extern const struct gamma_method drm_gamma_method; #endif #ifdef ENABLE_QUARTZ -extern const gamma_method_t quartz_gamma_method; +extern const struct gamma_method quartz_gamma_method; #endif #ifdef ENABLE_W32GDI -extern const gamma_method_t w32gdi_gamma_method; +extern const struct gamma_method w32gdi_gamma_method; #endif -extern const location_provider_t manual_location_provider; +extern const struct location_provider manual_location_provider; #ifdef ENABLE_GEOCLUE2 -extern const location_provider_t geoclue2_location_provider; +extern const struct location_provider geoclue2_location_provider; #endif #ifdef ENABLE_CORELOCATION -extern const location_provider_t corelocation_location_provider; +extern const struct location_provider corelocation_location_provider; #endif diff --git a/src/config-ini.c b/src/config-ini.c index 4f12610..b8566b9 100644 --- a/src/config-ini.c +++ b/src/config-ini.c @@ -16,31 +16,9 @@ Copyright (c) 2010-2018 Jon Lund Steffensen */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#ifndef _WIN32 -# include -#endif - +#include "common.h" #include "config-ini.h" -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif - #define MAX_CONFIG_PATH 4096 #define MAX_LINE_LENGTH 512 @@ -173,9 +151,9 @@ open_config_file(const char *filepath) } int -config_ini_init(config_ini_state_t *state, const char *filepath) +config_ini_init(struct config_ini_state *state, const char *filepath) { - config_ini_section_t *section = NULL; + struct config_ini_section *section = NULL; state->sections = NULL; FILE *f = open_config_file(filepath); @@ -215,7 +193,7 @@ config_ini_init(config_ini_state_t *state, const char *filepath) *end = '\0'; /* Create section. */ - section = malloc(sizeof(config_ini_section_t)); + section = malloc(sizeof(struct config_ini_section)); if (section == NULL) { fclose(f); config_ini_free(state); @@ -260,8 +238,8 @@ config_ini_init(config_ini_state_t *state, const char *filepath) } /* Create section. */ - config_ini_setting_t *setting = - malloc(sizeof(config_ini_setting_t)); + struct config_ini_setting *setting = + malloc(sizeof(struct config_ini_setting)); if (setting == NULL) { fclose(f); config_ini_free(state); @@ -303,16 +281,16 @@ config_ini_init(config_ini_state_t *state, const char *filepath) } void -config_ini_free(config_ini_state_t *state) +config_ini_free(struct config_ini_state *state) { - config_ini_section_t *section = state->sections; + struct config_ini_section *section = state->sections; while (section != NULL) { - config_ini_setting_t *setting = section->settings; - config_ini_section_t *section_prev = section; + struct config_ini_setting *setting = section->settings; + struct config_ini_section *section_prev = section; while (setting != NULL) { - config_ini_setting_t *setting_prev = setting; + struct config_ini_setting *setting_prev = setting; free(setting->name); free(setting->value); setting = setting->next; @@ -325,10 +303,10 @@ config_ini_free(config_ini_state_t *state) } } -config_ini_section_t * -config_ini_get_section(config_ini_state_t *state, const char *name) +struct config_ini_section * +config_ini_get_section(struct config_ini_state *state, const char *name) { - config_ini_section_t *section = state->sections; + struct config_ini_section *section = state->sections; while (section != NULL) { if (strcasecmp(section->name, name) == 0) { return section; diff --git a/src/config-ini.h b/src/config-ini.h index 5cdcc72..b50bf71 100644 --- a/src/config-ini.h +++ b/src/config-ini.h @@ -20,30 +20,26 @@ #ifndef REDSHIFT_CONFIG_INI_H #define REDSHIFT_CONFIG_INI_H -typedef struct _config_ini_section config_ini_section_t; -typedef struct _config_ini_setting config_ini_setting_t; - -struct _config_ini_setting { - config_ini_setting_t *next; +struct config_ini_setting { + struct config_ini_setting *next; char *name; char *value; }; -struct _config_ini_section { - config_ini_section_t *next; +struct config_ini_section { + struct config_ini_section *next; char *name; - config_ini_setting_t *settings; + struct config_ini_setting *settings; }; -typedef struct { - config_ini_section_t *sections; -} config_ini_state_t; +struct config_ini_state { + struct config_ini_section *sections; +}; -int config_ini_init(config_ini_state_t *state, const char *filepath); -void config_ini_free(config_ini_state_t *state); +int config_ini_init(struct config_ini_state *state, const char *filepath); +void config_ini_free(struct config_ini_state *state); -config_ini_section_t *config_ini_get_section(config_ini_state_t *state, - const char *name); +struct config_ini_section *config_ini_get_section(struct config_ini_state *state, const char *name); #endif /* ! REDSHIFT_CONFIG_INI_H */ diff --git a/src/config.mk b/src/config.mk index 6e1e732..a473366 100644 --- a/src/config.mk +++ b/src/config.mk @@ -1,6 +1,8 @@ PREFIX = /usr MANPREFIX = $(PREFIX)/share/man +PACKAGE = redshift-ng + CC = c99 PKGCONFIG = pkg-config @@ -16,6 +18,6 @@ LIBS_PKGCONFIG = $(DRM_LIBS) $(GEOCLUE_LIBS) $(RANDR_LIBS) $(VIDMODE_LIBS) CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_GNU_SOURCE\ -DENABLE_DRM -DENABLE_GEOCLUE2 -DENABLE_RANDR -DENABLE_VIDMODE\ - -DENABLE_COOPGAMMA + -DENABLE_COOPGAMMA -D'PACKAGE="$(PACKAGE)"' CFLAGS = $$($(PKGCONFIG_CFLAGS) $(LIBS_PKGCONFIG)) LDFLAGS = $$($(PKGCONFIG_LDFLAGS) $(LIBS_PKGCONFIG)) -lm -lcoopgamma -lred diff --git a/src/gamma-coopgamma.c b/src/gamma-coopgamma.c index d389e34..5b18c95 100644 --- a/src/gamma-coopgamma.c +++ b/src/gamma-coopgamma.c @@ -16,56 +16,35 @@ Copyright (c) 2016, 2025 Mattias Andrée */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#else -# define PACKAGE "redshift-ng" -#endif - -#include -#include -#include -#include -#include -#include - -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif - #include "common.h" #include -typedef struct { +struct coopgamma_output_id { char *edid; size_t index; -} coopgamma_output_id_t; +}; -typedef struct { +struct coopgamma_crtc_state { libcoopgamma_filter_t filter; libcoopgamma_ramps_t plain_ramps; size_t rampsize; -} coopgamma_crtc_state_t; +}; -typedef struct { +struct gamma_state { libcoopgamma_context_t ctx; - coopgamma_crtc_state_t *crtcs; + struct coopgamma_crtc_state *crtcs; size_t n_crtcs; char **methods; char *method; char *site; int64_t priority; int list_outputs; - coopgamma_output_id_t *outputs; + struct coopgamma_output_id *outputs; size_t n_outputs; size_t a_outputs; -} coopgamma_state_t; +}; struct signal_blockage { @@ -88,7 +67,7 @@ restore_signal_blockage(int signo, const struct signal_blockage *blockage) static int -update(coopgamma_state_t *state) +update(struct gamma_state *state) { for (size_t i = 0; i < state->n_crtcs; i++) libcoopgamma_set_gamma_sync(&state->crtcs[i].filter, &state->ctx); @@ -97,7 +76,7 @@ update(coopgamma_state_t *state) static void -print_error(coopgamma_state_t *state) +print_error(struct gamma_state *state) { const char* side = state->ctx.error.server_side ? _("server-side") : _("client-side"); if (state->ctx.error.custom) { @@ -119,12 +98,12 @@ print_error(coopgamma_state_t *state) static int -coopgamma_init(coopgamma_state_t **state) +coopgamma_init(struct gamma_state **state) { - *state = malloc(sizeof(coopgamma_state_t)); + *state = malloc(sizeof(struct gamma_state)); if (*state == NULL) return -1; - coopgamma_state_t *s = *state; + struct gamma_state *s = *state; struct signal_blockage signal_blockage; memset(s, 0, sizeof(*s)); @@ -152,7 +131,7 @@ coopgamma_init(coopgamma_state_t **state) } static int -coopgamma_start(coopgamma_state_t *state, program_mode_t mode) +coopgamma_start(struct gamma_state *state, enum program_mode mode) { struct signal_blockage signal_blockage; libcoopgamma_lifespan_t lifespan; @@ -261,7 +240,7 @@ coopgamma_start(coopgamma_state_t *state, program_mode_t mode) } for (i = 0; i < state->n_outputs; i++) { libcoopgamma_crtc_info_t info; - coopgamma_crtc_state_t *crtc = state->crtcs + state->n_crtcs; + struct coopgamma_crtc_state *crtc = state->crtcs + state->n_crtcs; crtc->filter.priority = state->priority; crtc->filter.crtc = state->outputs[i].edid; @@ -367,7 +346,7 @@ coopgamma_start(coopgamma_state_t *state, program_mode_t mode) } static void -coopgamma_free(coopgamma_state_t *state) +coopgamma_free(struct gamma_state *state) { free(state->methods); state->methods = NULL; @@ -414,7 +393,7 @@ coopgamma_print_help(FILE *f) } static int -coopgamma_set_option(coopgamma_state_t *state, const char *key, const char *value) +coopgamma_set_option(struct gamma_state *state, const char *key, const char *value) { size_t i; char *end; @@ -505,7 +484,7 @@ coopgamma_set_option(coopgamma_state_t *state, const char *key, const char *valu } static void -coopgamma_restore(coopgamma_state_t *state) +coopgamma_restore(struct gamma_state *state) { size_t i; for (i = 0; i < state->n_crtcs; i++) @@ -516,12 +495,14 @@ coopgamma_restore(coopgamma_state_t *state) } static int -coopgamma_set_temperature(coopgamma_state_t *state, const color_setting_t *setting) +coopgamma_set_temperature(struct gamma_state *state, const struct color_setting *setting, int perserve) { libcoopgamma_filter_t *filter; libcoopgamma_filter_t *last_filter = NULL; size_t i; + (void) perserve; + for (i = 0; i < state->n_crtcs; i++, last_filter = filter) { filter = &state->crtcs[i].filter; @@ -560,13 +541,13 @@ coopgamma_set_temperature(coopgamma_state_t *state, const color_setting_t *setti } -const gamma_method_t coopgamma_gamma_method = { +const struct gamma_method coopgamma_gamma_method = { "coopgamma", 1, - (gamma_method_init_func *)coopgamma_init, - (gamma_method_start_func *)coopgamma_start, - (gamma_method_free_func *)coopgamma_free, - (gamma_method_print_help_func *)coopgamma_print_help, - (gamma_method_set_option_func *)coopgamma_set_option, - (gamma_method_restore_func *)coopgamma_restore, - (gamma_method_set_temperature_func *)coopgamma_set_temperature + &coopgamma_init, + &coopgamma_start, + &coopgamma_free, + &coopgamma_print_help, + &coopgamma_set_option, + &coopgamma_restore, + &coopgamma_set_temperature }; diff --git a/src/gamma-drm.c b/src/gamma-drm.c index 30d1f23..7ed223d 100644 --- a/src/gamma-drm.c +++ b/src/gamma-drm.c @@ -14,66 +14,45 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see . - Copyright (c) 2014 Mattias Andrée - Copyright (c) 2017 Jon Lund Steffensen + Copyright (c) 2014, 2025 Mattias Andrée + Copyright (c) 2017 Jon Lund Steffensen */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif - -#ifndef O_CLOEXEC - #define O_CLOEXEC 02000000 -#endif +#include "common.h" #include #include -#include "common.h" +#ifndef O_CLOEXEC +# define O_CLOEXEC 02000000 +#endif -typedef struct { +struct drm_crtc_state { int crtc_num; int crtc_id; int gamma_size; - uint16_t* r_gamma; - uint16_t* g_gamma; - uint16_t* b_gamma; -} drm_crtc_state_t; + uint16_t *r_gamma; + uint16_t *g_gamma; + uint16_t *b_gamma; +}; -typedef struct { +struct gamma_state { int card_num; int crtc_num; int fd; - drmModeRes* res; - drm_crtc_state_t* crtcs; -} drm_state_t; + drmModeRes *res; + struct drm_crtc_state *crtcs; +}; static int -drm_init(drm_state_t **state) +drm_init(struct gamma_state **state) { /* Initialize state. */ - *state = malloc(sizeof(drm_state_t)); + *state = malloc(sizeof(struct gamma_state)); if (*state == NULL) return -1; - drm_state_t *s = *state; + struct gamma_state *s = *state; s->card_num = 0; s->crtc_num = -1; s->fd = -1; @@ -84,7 +63,7 @@ drm_init(drm_state_t **state) } static int -drm_start(drm_state_t *state, program_mode_t mode) +drm_start(struct gamma_state *state, enum program_mode mode) { /* Acquire access to a graphics card. */ long maxlen = strlen(DRM_DIR_NAME) + strlen(DRM_DEV_NAME) + 10; @@ -130,7 +109,7 @@ drm_start(drm_state_t *state, program_mode_t mode) return -1; } - state->crtcs = malloc(2 * sizeof(drm_crtc_state_t)); + state->crtcs = malloc(2 * sizeof(struct drm_crtc_state)); state->crtcs[1].crtc_num = -1; state->crtcs->crtc_num = state->crtc_num; @@ -141,7 +120,7 @@ drm_start(drm_state_t *state, program_mode_t mode) state->crtcs->b_gamma = NULL; } else { int crtc_num; - state->crtcs = malloc((crtc_count + 1) * sizeof(drm_crtc_state_t)); + state->crtcs = malloc((crtc_count + 1) * sizeof(struct drm_crtc_state)); state->crtcs[crtc_count].crtc_num = -1; for (crtc_num = 0; crtc_num < crtc_count; crtc_num++) { state->crtcs[crtc_num].crtc_num = crtc_num; @@ -154,7 +133,7 @@ drm_start(drm_state_t *state, program_mode_t mode) } /* Load CRTC information and gamma ramps. */ - drm_crtc_state_t *crtcs = state->crtcs; + struct drm_crtc_state *crtcs = state->crtcs; for (; crtcs->crtc_num >= 0; crtcs++) { crtcs->crtc_id = state->res->crtcs[crtcs->crtc_num]; drmModeCrtc* crtc_info = drmModeGetCrtc(state->fd, crtcs->crtc_id); @@ -202,9 +181,9 @@ drm_start(drm_state_t *state, program_mode_t mode) } static void -drm_restore(drm_state_t *state) +drm_restore(struct gamma_state *state) { - drm_crtc_state_t *crtcs = state->crtcs; + struct drm_crtc_state *crtcs = state->crtcs; while (crtcs->crtc_num >= 0) { if (crtcs->r_gamma != NULL) { drmModeCrtcSetGamma(state->fd, crtcs->crtc_id, crtcs->gamma_size, @@ -215,10 +194,10 @@ drm_restore(drm_state_t *state) } static void -drm_free(drm_state_t *state) +drm_free(struct gamma_state *state) { if (state->crtcs != NULL) { - drm_crtc_state_t *crtcs = state->crtcs; + struct drm_crtc_state *crtcs = state->crtcs; while (crtcs->crtc_num >= 0) { free(crtcs->r_gamma); crtcs->crtc_num = -1; @@ -253,7 +232,7 @@ drm_print_help(FILE *f) } static int -drm_set_option(drm_state_t *state, const char *key, const char *value) +drm_set_option(struct gamma_state *state, const char *key, const char *value) { if (strcasecmp(key, "card") == 0) { state->card_num = atoi(value); @@ -273,9 +252,9 @@ drm_set_option(drm_state_t *state, const char *key, const char *value) static int drm_set_temperature( - drm_state_t *state, const color_setting_t *setting, int preserve) + struct gamma_state *state, const struct color_setting *setting, int preserve) { - drm_crtc_state_t *crtcs = state->crtcs; + struct drm_crtc_state *crtcs = state->crtcs; uint32_t last_gamma_size = 0; uint16_t *r_gamma = NULL; uint16_t *g_gamma = NULL; @@ -322,13 +301,13 @@ drm_set_temperature( } -const gamma_method_t drm_gamma_method = { +const struct gamma_method drm_gamma_method = { "drm", 0, - (gamma_method_init_func *)drm_init, - (gamma_method_start_func *)drm_start, - (gamma_method_free_func *)drm_free, - (gamma_method_print_help_func *)drm_print_help, - (gamma_method_set_option_func *)drm_set_option, - (gamma_method_restore_func *)drm_restore, - (gamma_method_set_temperature_func *)drm_set_temperature + &drm_init, + &drm_start, + &drm_free, + &drm_print_help, + &drm_set_option, + &drm_restore, + &drm_set_temperature }; diff --git a/src/gamma-dummy.c b/src/gamma-dummy.c index 066ae96..d87c2dd 100644 --- a/src/gamma-dummy.c +++ b/src/gamma-dummy.c @@ -16,42 +16,30 @@ Copyright (c) 2013-2017 Jon Lund Steffensen */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif - #include "common.h" static int -gamma_dummy_init(void **state) +gamma_dummy_init(struct gamma_state **state) { *state = NULL; return 0; } static int -gamma_dummy_start(void *state, program_mode_t mode) +gamma_dummy_start(struct gamma_state *state, enum program_mode mode) { fputs(_("WARNING: Using dummy gamma method! Display will not be affected by this gamma method.\n"), stderr); return 0; } static void -gamma_dummy_restore(void *state) +gamma_dummy_restore(struct gamma_state *state) { } static void -gamma_dummy_free(void *state) +gamma_dummy_free(struct gamma_state *state) { } @@ -63,7 +51,7 @@ gamma_dummy_print_help(FILE *f) } static int -gamma_dummy_set_option(void *state, const char *key, const char *value) +gamma_dummy_set_option(struct gamma_state *state, const char *key, const char *value) { fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key); return -1; @@ -71,20 +59,20 @@ gamma_dummy_set_option(void *state, const char *key, const char *value) static int gamma_dummy_set_temperature( - void *state, const color_setting_t *setting, int preserve) + struct gamma_state *state, const struct color_setting *setting, int preserve) { printf(_("Temperature: %i\n"), setting->temperature); return 0; } -const gamma_method_t dummy_gamma_method = { +const struct gamma_method dummy_gamma_method = { "dummy", 0, - (gamma_method_init_func *)gamma_dummy_init, - (gamma_method_start_func *)gamma_dummy_start, - (gamma_method_free_func *)gamma_dummy_free, - (gamma_method_print_help_func *)gamma_dummy_print_help, - (gamma_method_set_option_func *)gamma_dummy_set_option, - (gamma_method_restore_func *)gamma_dummy_restore, - (gamma_method_set_temperature_func *)gamma_dummy_set_temperature + &gamma_dummy_init, + &gamma_dummy_start, + &gamma_dummy_free, + &gamma_dummy_print_help, + &gamma_dummy_set_option, + &gamma_dummy_restore, + &gamma_dummy_set_temperature }; diff --git a/src/gamma-quartz.c b/src/gamma-quartz.c index 74ceaf0..c8e39d6 100644 --- a/src/gamma-quartz.c +++ b/src/gamma-quartz.c @@ -15,54 +15,39 @@ along with Redshift. If not, see . Copyright (c) 2014-2017 Jon Lund Steffensen + Copyright (c) 2025 Mattias Andrée */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include +#include "common.h" #include -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif - -#include "gamma-quartz.h" -#include "colorramp.h" - -typedef struct { +struct quartz_display_state { CGDirectDisplayID display; uint32_t ramp_size; float *saved_ramps; -} quartz_display_state_t; +}; -typedef struct { - quartz_display_state_t *displays; +struct gamma_state { + struct quartz_display_state *displays; uint32_t display_count; -} quartz_state_t; +}; static int -quartz_init(quartz_state_t **state) +quartz_init(struct gamma_state **state) { - *state = malloc(sizeof(quartz_state_t)); + *state = malloc(sizeof(struct gamma_state)); if (*state == NULL) return -1; - quartz_state_t *s = *state; + struct gamma_state *s = *state; s->displays = NULL; return 0; } static int -quartz_start(quartz_state_t *state, program_mode_t mode) +quartz_start(struct gamma_state *state, program_mode_t mode) { CGError error; uint32_t display_count; @@ -90,7 +75,7 @@ quartz_start(quartz_state_t *state, program_mode_t mode) /* Allocate list of display state */ state->displays = malloc(display_count * - sizeof(quartz_display_state_t)); + sizeof(struct quartz_display_state)); if (state->displays == NULL) { perror("malloc"); free(displays); @@ -147,13 +132,13 @@ quartz_start(quartz_state_t *state, program_mode_t mode) } static void -quartz_restore(quartz_state_t *state) +quartz_restore(struct gamma_state *state) { CGDisplayRestoreColorSyncSettings(); } static void -quartz_free(quartz_state_t *state) +quartz_free(struct gamma_state *state) { if (state->displays != NULL) { for (int i = 0; i < state->display_count; i++) { @@ -172,7 +157,7 @@ quartz_print_help(FILE *f) } static int -quartz_set_option(quartz_state_t *state, const char *key, const char *value) +quartz_set_option(struct gamma_state *state, const char *key, const char *value) { if (strcasecmp(key, "preserve") == 0) { fprintf(stderr, _("Parameter `%s` is now always on; " @@ -189,7 +174,7 @@ quartz_set_option(quartz_state_t *state, const char *key, const char *value) static void quartz_set_temperature_for_display( - quartz_state_t *state, int display_index, + struct gamma_state *state, int display_index, const color_setting_t *setting, int preserve) { CGDirectDisplayID display = state->displays[display_index].display; @@ -236,7 +221,7 @@ quartz_set_temperature_for_display( static int quartz_set_temperature( - quartz_state_t *state, const color_setting_t *setting, int preserve) + struct gamma_state *state, const color_setting_t *setting, int preserve) { for (int i = 0; i < state->display_count; i++) { quartz_set_temperature_for_display( @@ -247,13 +232,13 @@ quartz_set_temperature( } -const gamma_method_t quartz_gamma_method = { +const struct gamma_method quartz_gamma_method = { "quartz", 1, - (gamma_method_init_func *)quartz_init, - (gamma_method_start_func *)quartz_start, - (gamma_method_free_func *)quartz_free, - (gamma_method_print_help_func *)quartz_print_help, - (gamma_method_set_option_func *)quartz_set_option, - (gamma_method_restore_func *)quartz_restore, - (gamma_method_set_temperature_func *)quartz_set_temperature + &quartz_init, + &quartz_start, + &quartz_free, + &quartz_print_help, + &quartz_set_option, + &quartz_restore, + &quartz_set_temperature }; diff --git a/src/gamma-randr.c b/src/gamma-randr.c index 4a2c907..713139a 100644 --- a/src/gamma-randr.c +++ b/src/gamma-randr.c @@ -15,42 +15,25 @@ along with Redshift. If not, see . Copyright (c) 2010-2017 Jon Lund Steffensen + Copyright (c) 2025 Mattias Andrée */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include -#include - -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif +#include "common.h" #include #include -#include "common.h" - #define RANDR_VERSION_MAJOR 1 #define RANDR_VERSION_MINOR 3 -typedef struct { +struct randr_crtc_state { xcb_randr_crtc_t crtc; unsigned int ramp_size; uint16_t *saved_ramps; -} randr_crtc_state_t; +}; -typedef struct { +struct gamma_state { xcb_connection_t *conn; xcb_screen_t *screen; int preferred_screen; @@ -58,18 +41,18 @@ typedef struct { int crtc_num_count; int* crtc_num; unsigned int crtc_count; - randr_crtc_state_t *crtcs; -} randr_state_t; + struct randr_crtc_state *crtcs; +}; static int -randr_init(randr_state_t **state) +randr_init(struct gamma_state **state) { /* Initialize state. */ - *state = malloc(sizeof(randr_state_t)); + *state = malloc(sizeof(struct gamma_state)); if (*state == NULL) return -1; - randr_state_t *s = *state; + struct gamma_state *s = *state; s->screen_num = -1; s->crtc_num = NULL; @@ -116,7 +99,7 @@ randr_init(randr_state_t **state) } static int -randr_start(randr_state_t *state, program_mode_t mode) +randr_start(struct gamma_state *state, enum program_mode mode) { xcb_generic_error_t *error; @@ -159,7 +142,7 @@ randr_start(randr_state_t *state, program_mode_t mode) } state->crtc_count = res_reply->num_crtcs; - state->crtcs = calloc(state->crtc_count, sizeof(randr_crtc_state_t)); + state->crtcs = calloc(state->crtc_count, sizeof(struct randr_crtc_state)); if (state->crtcs == NULL) { perror("malloc"); state->crtc_count = 0; @@ -253,7 +236,7 @@ randr_start(randr_state_t *state, program_mode_t mode) } static void -randr_restore(randr_state_t *state) +randr_restore(struct gamma_state *state) { xcb_generic_error_t *error; @@ -282,7 +265,7 @@ randr_restore(randr_state_t *state) } static void -randr_free(randr_state_t *state) +randr_free(struct gamma_state *state) { /* Free CRTC state */ for (int i = 0; i < state->crtc_count; i++) { @@ -313,7 +296,7 @@ randr_print_help(FILE *f) } static int -randr_set_option(randr_state_t *state, const char *key, const char *value) +randr_set_option(struct gamma_state *state, const char *key, const char *value) { if (strcasecmp(key, "screen") == 0) { state->screen_num = atoi(value); @@ -377,7 +360,7 @@ randr_set_option(randr_state_t *state, const char *key, const char *value) static int randr_set_temperature_for_crtc( - randr_state_t *state, int crtc_num, const color_setting_t *setting, + struct gamma_state *state, int crtc_num, const struct color_setting *setting, int preserve) { xcb_generic_error_t *error; @@ -447,7 +430,7 @@ randr_set_temperature_for_crtc( static int randr_set_temperature( - randr_state_t *state, const color_setting_t *setting, int preserve) + struct gamma_state *state, const struct color_setting *setting, int preserve) { int r; @@ -471,13 +454,13 @@ randr_set_temperature( } -const gamma_method_t randr_gamma_method = { +const struct gamma_method randr_gamma_method = { "randr", 1, - (gamma_method_init_func *)randr_init, - (gamma_method_start_func *)randr_start, - (gamma_method_free_func *)randr_free, - (gamma_method_print_help_func *)randr_print_help, - (gamma_method_set_option_func *)randr_set_option, - (gamma_method_restore_func *)randr_restore, - (gamma_method_set_temperature_func *)randr_set_temperature + &randr_init, + &randr_start, + &randr_free, + &randr_print_help, + &randr_set_option, + &randr_restore, + &randr_set_temperature }; diff --git a/src/gamma-vidmode.c b/src/gamma-vidmode.c index f718ccc..164437f 100644 --- a/src/gamma-vidmode.c +++ b/src/gamma-vidmode.c @@ -15,45 +15,29 @@ along with Redshift. If not, see . Copyright (c) 2010-2017 Jon Lund Steffensen + Copyright (c) 2025 Mattias Andrée */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include - -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif +#include "common.h" #include #include -#include "common.h" - -typedef struct { +struct gamma_state { Display *display; int screen_num; int ramp_size; uint16_t *saved_ramps; -} vidmode_state_t; +}; static int -vidmode_init(vidmode_state_t **state) +vidmode_init(struct gamma_state **state) { - *state = malloc(sizeof(vidmode_state_t)); + *state = malloc(sizeof(struct gamma_state)); if (*state == NULL) return -1; - vidmode_state_t *s = *state; + struct gamma_state *s = *state; s->screen_num = -1; s->saved_ramps = NULL; @@ -68,7 +52,7 @@ vidmode_init(vidmode_state_t **state) } static int -vidmode_start(vidmode_state_t *state, program_mode_t mode) +vidmode_start(struct gamma_state *state, enum program_mode mode) { int r; int screen_num = state->screen_num; @@ -125,7 +109,7 @@ vidmode_start(vidmode_state_t *state, program_mode_t mode) } static void -vidmode_free(vidmode_state_t *state) +vidmode_free(struct gamma_state *state) { /* Free saved ramps */ free(state->saved_ramps); @@ -150,7 +134,7 @@ vidmode_print_help(FILE *f) } static int -vidmode_set_option(vidmode_state_t *state, const char *key, const char *value) +vidmode_set_option(struct gamma_state *state, const char *key, const char *value) { if (strcasecmp(key, "screen") == 0) { state->screen_num = atoi(value); @@ -168,7 +152,7 @@ vidmode_set_option(vidmode_state_t *state, const char *key, const char *value) } static void -vidmode_restore(vidmode_state_t *state) +vidmode_restore(struct gamma_state *state) { uint16_t *gamma_r = &state->saved_ramps[0*state->ramp_size]; uint16_t *gamma_g = &state->saved_ramps[1*state->ramp_size]; @@ -186,7 +170,7 @@ vidmode_restore(vidmode_state_t *state) static int vidmode_set_temperature( - vidmode_state_t *state, const color_setting_t *setting, int preserve) + struct gamma_state *state, const struct color_setting *setting, int preserve) { int r; @@ -236,13 +220,13 @@ vidmode_set_temperature( } -const gamma_method_t vidmode_gamma_method = { +const struct gamma_method vidmode_gamma_method = { "vidmode", 1, - (gamma_method_init_func *)vidmode_init, - (gamma_method_start_func *)vidmode_start, - (gamma_method_free_func *)vidmode_free, - (gamma_method_print_help_func *)vidmode_print_help, - (gamma_method_set_option_func *)vidmode_set_option, - (gamma_method_restore_func *)vidmode_restore, - (gamma_method_set_temperature_func *)vidmode_set_temperature + &vidmode_init, + &vidmode_start, + &vidmode_free, + &vidmode_print_help, + &vidmode_set_option, + &vidmode_restore, + &vidmode_set_temperature }; diff --git a/src/gamma-w32gdi.c b/src/gamma-w32gdi.c index da5461e..87568f9 100644 --- a/src/gamma-w32gdi.c +++ b/src/gamma-w32gdi.c @@ -15,14 +15,9 @@ along with Redshift. If not, see . Copyright (c) 2010-2017 Jon Lund Steffensen + Copyright (c) 2025 Mattias Andrée */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include +#include "common.h" #ifndef WINVER # define WINVER 0x0500 @@ -30,39 +25,29 @@ #include #include -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif - -#include "gamma-w32gdi.h" -#include "colorramp.h" - #define GAMMA_RAMP_SIZE 256 #define MAX_ATTEMPTS 10 -typedef struct { +struct gamma_state { WORD *saved_ramps; -} w32gdi_state_t; +}; static int -w32gdi_init(w32gdi_state_t **state) +w32gdi_init(struct gamma_state **state) { - *state = malloc(sizeof(w32gdi_state_t)); + *state = malloc(sizeof(struct gamma_state)); if (state == NULL) return -1; - w32gdi_state_t *s = *state; + struct gamma_state *s = *state; s->saved_ramps = NULL; return 0; } static int -w32gdi_start(w32gdi_state_t *state, program_mode_t mode) +w32gdi_start(struct gamma_state *state, program_mode_t mode) { BOOL r; @@ -104,7 +89,7 @@ w32gdi_start(w32gdi_state_t *state, program_mode_t mode) } static void -w32gdi_free(w32gdi_state_t *state) +w32gdi_free(struct gamma_state *state) { /* Free saved ramps */ free(state->saved_ramps); @@ -121,7 +106,7 @@ w32gdi_print_help(FILE *f) } static int -w32gdi_set_option(w32gdi_state_t *state, const char *key, const char *value) +w32gdi_set_option(struct gamma_state *state, const char *key, const char *value) { if (strcasecmp(key, "preserve") == 0) { fprintf(stderr, _("Parameter `%s` is now always on; " @@ -137,7 +122,7 @@ w32gdi_set_option(w32gdi_state_t *state, const char *key, const char *value) } static void -w32gdi_restore(w32gdi_state_t *state) +w32gdi_restore(struct gamma_state *state) { /* Open device context */ HDC hDC = GetDC(NULL); @@ -162,7 +147,7 @@ w32gdi_restore(w32gdi_state_t *state) static int w32gdi_set_temperature( - w32gdi_state_t *state, const color_setting_t *setting, int preserve) + struct gamma_state *state, const color_setting_t *setting, int preserve) { BOOL r; @@ -227,13 +212,13 @@ w32gdi_set_temperature( } -const gamma_method_t w32gdi_gamma_method = { +const struct gamma_method w32gdi_gamma_method = { "wingdi", 1, - (gamma_method_init_func *)w32gdi_init, - (gamma_method_start_func *)w32gdi_start, - (gamma_method_free_func *)w32gdi_free, - (gamma_method_print_help_func *)w32gdi_print_help, - (gamma_method_set_option_func *)w32gdi_set_option, - (gamma_method_restore_func *)w32gdi_restore, - (gamma_method_set_temperature_func *)w32gdi_set_temperature + &w32gdi_init, + &w32gdi_start, + &w32gdi_free, + &w32gdi_print_help, + &w32gdi_set_option, + &w32gdi_restore, + &w32gdi_set_temperature }; diff --git a/src/hooks.c b/src/hooks.c index cb14f60..1bd3efe 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -16,16 +16,6 @@ Copyright (c) 2014 Jon Lund Steffensen */ - -#include -#include -#include -#include -#include -#ifndef _WIN32 -# include -#endif - #include "common.h" #define MAX_HOOK_PATH 4096 @@ -71,7 +61,7 @@ open_hooks_dir(char *hp) /* Run hooks with a signal that the period changed. */ void -hooks_signal_period_change(period_t prev_period, period_t period) +hooks_signal_period_change(enum period prev_period, enum period period) { char hooksdir_path[MAX_HOOK_PATH]; DIR *hooks_dir = open_hooks_dir(hooksdir_path); diff --git a/src/location-corelocation.m b/src/location-corelocation.m index 10d7acd..87eb0de 100644 --- a/src/location-corelocation.m +++ b/src/location-corelocation.m @@ -16,30 +16,13 @@ Copyright (c) 2014-2017 Jon Lund Steffensen */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "common.h" #import #import -#include "location-corelocation.h" -#include "pipeutils.h" -#include "redshift.h" - -#include -#include - -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif - -typedef struct { +struct location_state { NSThread *thread; NSLock *lock; int pipe_fd_read; @@ -48,12 +31,12 @@ typedef struct { int error; float latitude; float longitude; -} location_corelocation_state_t; +}; @interface LocationDelegate : NSObject @property (strong, nonatomic) CLLocationManager *locationManager; -@property (nonatomic) location_corelocation_state_t *state; +@property (nonatomic) struct location_state *state; @end @implementation LocationDelegate; @@ -157,7 +140,7 @@ pipe_close_callback( @interface LocationThread : NSThread -@property (nonatomic) location_corelocation_state_t *state; +@property (nonatomic) struct location_state *state; @end @implementation LocationThread; @@ -194,15 +177,15 @@ pipe_close_callback( static int -location_corelocation_init(location_corelocation_state_t **state) +location_corelocation_init(struct location_state **state) { - *state = malloc(sizeof(location_corelocation_state_t)); + *state = malloc(sizeof(struct location_state)); if (*state == NULL) return -1; return 0; } static int -location_corelocation_start(location_corelocation_state_t *state) +location_corelocation_start(struct location_state *state) { state->pipe_fd_read = -1; state->pipe_fd_write = -1; @@ -235,7 +218,7 @@ location_corelocation_start(location_corelocation_state_t *state) } static void -location_corelocation_free(location_corelocation_state_t *state) +location_corelocation_free(struct location_state *state) { if (state->pipe_fd_read != -1) { close(state->pipe_fd_read); @@ -253,21 +236,21 @@ location_corelocation_print_help(FILE *f) static int location_corelocation_set_option( - location_corelocation_state_t *state, const char *key, const char *value) + struct location_state *state, const char *key, const char *value) { fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key); return -1; } static int -location_corelocation_get_fd(location_corelocation_state_t *state) +location_corelocation_get_fd(struct location_state *state) { return state->pipe_fd_read; } static int location_corelocation_handle( - location_corelocation_state_t *state, + struct location_state *state, location_t *location, int *available) { pipeutils_handle_signal(state->pipe_fd_read); diff --git a/src/location-geoclue2.c b/src/location-geoclue2.c index c6c2bda..835b4c4 100644 --- a/src/location-geoclue2.c +++ b/src/location-geoclue2.c @@ -15,32 +15,18 @@ along with Redshift. If not, see . Copyright (c) 2014-2017 Jon Lund Steffensen + Copyright (c) 2025 Mattias Andrée */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include +#include "common.h" #include #include #include -#include "common.h" - -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif - #define DBUS_ACCESS_ERROR "org.freedesktop.DBus.Error.AccessDenied" -typedef struct { +struct location_state { GMainLoop *loop; GThread *thread; GMutex lock; @@ -50,7 +36,7 @@ typedef struct { int error; float latitude; float longitude; -} location_geoclue2_state_t; +}; /* Print the message explaining denial from GeoClue. */ @@ -67,7 +53,7 @@ print_denial_message() /* Indicate an unrecoverable error during GeoClue2 communication. */ static void -mark_error(location_geoclue2_state_t *state) +mark_error(struct location_state *state) { g_mutex_lock(&state->lock); @@ -84,7 +70,7 @@ geoclue_client_signal_cb(GDBusProxy *client, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data) { - location_geoclue2_state_t *state = user_data; + struct location_state *state = user_data; /* Only handle LocationUpdated signals */ if (g_strcmp0(signal_name, "LocationUpdated") != 0) { @@ -136,7 +122,7 @@ static void on_name_appeared(GDBusConnection *conn, const gchar *name, const gchar *name_owner, gpointer user_data) { - location_geoclue2_state_t *state = user_data; + struct location_state *state = user_data; /* Obtain GeoClue Manager */ GError *error = NULL; @@ -277,7 +263,7 @@ static void on_name_vanished(GDBusConnection *connection, const gchar *name, gpointer user_data) { - location_geoclue2_state_t *state = user_data; + struct location_state *state = user_data; g_mutex_lock(&state->lock); @@ -292,7 +278,7 @@ on_name_vanished(GDBusConnection *connection, const gchar *name, static gboolean on_pipe_closed(GIOChannel *channel, GIOCondition condition, gpointer user_data) { - location_geoclue2_state_t *state = user_data; + struct location_state *state = user_data; g_main_loop_quit(state->loop); return FALSE; @@ -303,7 +289,7 @@ on_pipe_closed(GIOChannel *channel, GIOCondition condition, gpointer user_data) static void * run_geoclue2_loop(void *state_) { - location_geoclue2_state_t *state = state_; + struct location_state *state = state_; GMainContext *context = g_main_context_new(); g_main_context_push_thread_default(context); @@ -340,18 +326,18 @@ run_geoclue2_loop(void *state_) } static int -location_geoclue2_init(location_geoclue2_state_t **state) +location_geoclue2_init(struct location_state **state) { #if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init(); #endif - *state = malloc(sizeof(location_geoclue2_state_t)); + *state = malloc(sizeof(struct location_state)); if (*state == NULL) return -1; return 0; } static int -location_geoclue2_start(location_geoclue2_state_t *state) +location_geoclue2_start(struct location_state *state) { state->pipe_fd_read = -1; state->pipe_fd_write = -1; @@ -380,7 +366,7 @@ location_geoclue2_start(location_geoclue2_state_t *state) } static void -location_geoclue2_free(location_geoclue2_state_t *state) +location_geoclue2_free(struct location_state *state) { if (state->pipe_fd_read != -1) { close(state->pipe_fd_read); @@ -404,7 +390,7 @@ location_geoclue2_print_help(FILE *f) } static int -location_geoclue2_set_option(location_geoclue2_state_t *state, +location_geoclue2_set_option(struct location_state *state, const char *key, const char *value) { fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key); @@ -412,15 +398,15 @@ location_geoclue2_set_option(location_geoclue2_state_t *state, } static int -location_geoclue2_get_fd(location_geoclue2_state_t *state) +location_geoclue2_get_fd(struct location_state *state) { return state->pipe_fd_read; } static int location_geoclue2_handle( - location_geoclue2_state_t *state, - location_t *location, int *available) + struct location_state *state, + struct location *location, int *available) { pipeutils_handle_signal(state->pipe_fd_read); @@ -439,13 +425,13 @@ location_geoclue2_handle( } -const location_provider_t geoclue2_location_provider = { +const struct location_provider geoclue2_location_provider = { "geoclue2", - (location_provider_init_func *)location_geoclue2_init, - (location_provider_start_func *)location_geoclue2_start, - (location_provider_free_func *)location_geoclue2_free, - (location_provider_print_help_func *)location_geoclue2_print_help, - (location_provider_set_option_func *)location_geoclue2_set_option, - (location_provider_get_fd_func *)location_geoclue2_get_fd, - (location_provider_handle_func *)location_geoclue2_handle + &location_geoclue2_init, + &location_geoclue2_start, + &location_geoclue2_free, + &location_geoclue2_print_help, + &location_geoclue2_set_option, + &location_geoclue2_get_fd, + &location_geoclue2_handle }; diff --git a/src/location-manual.c b/src/location-manual.c index 7ab9162..0048128 100644 --- a/src/location-manual.c +++ b/src/location-manual.c @@ -15,40 +15,23 @@ along with Redshift. If not, see . Copyright (c) 2010-2017 Jon Lund Steffensen + Copyright (c) 2025 Mattias Andrée */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include -#include - #include "common.h" -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif - -typedef struct { - location_t loc; -} location_manual_state_t; +struct location_state { + struct location loc; +}; static int -location_manual_init(location_manual_state_t **state) +location_manual_init(struct location_state **state) { - *state = malloc(sizeof(location_manual_state_t)); + *state = malloc(sizeof(struct location_state)); if (*state == NULL) return -1; - location_manual_state_t *s = *state; + struct location_state *s = *state; s->loc.lat = NAN; s->loc.lon = NAN; @@ -56,7 +39,7 @@ location_manual_init(location_manual_state_t **state) } static int -location_manual_start(location_manual_state_t *state) +location_manual_start(struct location_state *state) { /* Latitude and longitude must be set */ if (isnan(state->loc.lat) || isnan(state->loc.lon)) { @@ -68,7 +51,7 @@ location_manual_start(location_manual_state_t *state) } static void -location_manual_free(location_manual_state_t *state) +location_manual_free(struct location_state *state) { free(state); } @@ -90,7 +73,7 @@ location_manual_print_help(FILE *f) } static int -location_manual_set_option(location_manual_state_t *state, const char *key, +location_manual_set_option(struct location_state *state, const char *key, const char *value) { /* Parse float value */ @@ -115,14 +98,14 @@ location_manual_set_option(location_manual_state_t *state, const char *key, } static int -location_manual_get_fd(location_manual_state_t *state) +location_manual_get_fd(struct location_state *state) { return -1; } static int location_manual_handle( - location_manual_state_t *state, location_t *location, int *available) + struct location_state *state, struct location *location, int *available) { *location = state->loc; *available = 1; @@ -131,13 +114,13 @@ location_manual_handle( } -const location_provider_t manual_location_provider = { +const struct location_provider manual_location_provider = { "manual", - (location_provider_init_func *)location_manual_init, - (location_provider_start_func *)location_manual_start, - (location_provider_free_func *)location_manual_free, - (location_provider_print_help_func *)location_manual_print_help, - (location_provider_set_option_func *)location_manual_set_option, - (location_provider_get_fd_func *)location_manual_get_fd, - (location_provider_handle_func *)location_manual_handle + &location_manual_init, + &location_manual_start, + &location_manual_free, + &location_manual_print_help, + &location_manual_set_option, + &location_manual_get_fd, + &location_manual_handle }; diff --git a/src/options.c b/src/options.c index 28c9149..dc38e2a 100644 --- a/src/options.c +++ b/src/options.c @@ -16,24 +16,6 @@ Copyright (c) 2017 Jon Lund Steffensen */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include -#include - -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif - #include "common.h" #include "config-ini.h" #include "options.h" @@ -123,7 +105,7 @@ parse_transition_time(const char *str, const char **end) failure, otherwise zero. Parsed start and end times are returned as seconds since midnight. */ static int -parse_transition_range(const char *str, time_range_t *range) +parse_transition_range(const char *str, struct time_range *range) { const char *next = NULL; int start_time = parse_transition_time(str, &next); @@ -217,7 +199,7 @@ print_help(const char *program_name) /* Print list of adjustment methods. */ static void -print_method_list(const gamma_method_t *gamma_methods) +print_method_list(const struct gamma_method *gamma_methods) { fputs(_("Available adjustment methods:\n"), stdout); for (int i = 0; gamma_methods[i].name != NULL; i++) { @@ -233,7 +215,7 @@ print_method_list(const gamma_method_t *gamma_methods) /* Print list of location providers. */ static void -print_provider_list(const location_provider_t location_providers[]) +print_provider_list(const struct location_provider location_providers[]) { fputs(_("Available location providers:\n"), stdout); for (int i = 0; location_providers[i].name != NULL; i++) { @@ -248,12 +230,12 @@ print_provider_list(const location_provider_t location_providers[]) } /* Return the gamma method with the given name. */ -static const gamma_method_t * -find_gamma_method(const gamma_method_t gamma_methods[], const char *name) +static const struct gamma_method * +find_gamma_method(const struct gamma_method gamma_methods[], const char *name) { - const gamma_method_t *method = NULL; + const struct gamma_method *method = NULL; for (int i = 0; gamma_methods[i].name != NULL; i++) { - const gamma_method_t *m = &gamma_methods[i]; + const struct gamma_method *m = &gamma_methods[i]; if (strcasecmp(name, m->name) == 0) { method = m; break; @@ -264,13 +246,13 @@ find_gamma_method(const gamma_method_t gamma_methods[], const char *name) } /* Return location provider with the given name. */ -static const location_provider_t * +static const struct location_provider * find_location_provider( - const location_provider_t location_providers[], const char *name) + const struct location_provider location_providers[], const char *name) { - const location_provider_t *provider = NULL; + const struct location_provider *provider = NULL; for (int i = 0; location_providers[i].name != NULL; i++) { - const location_provider_t *p = &location_providers[i]; + const struct location_provider *p = &location_providers[i]; if (strcasecmp(name, p->name) == 0) { provider = p; break; @@ -283,7 +265,7 @@ find_location_provider( /* Initialize options struct. */ void -options_init(options_t *options) +options_init(struct options *options) { options->config_filepath = NULL; @@ -325,9 +307,9 @@ options_init(options_t *options) /* Parse a single option from the command-line. */ static int parse_command_line_option( - const char option, char *value, options_t *options, - const char *program_name, const gamma_method_t *gamma_methods, - const location_provider_t *location_providers) + const char option, char *value, struct options *options, + const char *program_name, const struct gamma_method *gamma_methods, + const struct location_provider *location_providers) { int r; char *s; @@ -486,9 +468,9 @@ parse_command_line_option( /* Parse command line arguments. */ void options_parse_args( - options_t *options, int argc, char *argv[], - const gamma_method_t *gamma_methods, - const location_provider_t *location_providers) + struct options *options, int argc, char *argv[], + const struct gamma_method *gamma_methods, + const struct location_provider *location_providers) { const char* program_name = argv[0]; int opt; @@ -504,9 +486,9 @@ options_parse_args( /* Parse a single key-value pair from the configuration file. */ static int parse_config_file_option( - const char *key, const char *value, options_t *options, - const gamma_method_t *gamma_methods, - const location_provider_t *location_providers) + const char *key, const char *value, struct options *options, + const struct gamma_method *gamma_methods, + const struct location_provider *location_providers) { if (strcasecmp(key, "temp-day") == 0) { if (options->scheme.day.temperature < 0) { @@ -627,16 +609,16 @@ parse_config_file_option( /* Parse options defined in the config file. */ void options_parse_config_file( - options_t *options, config_ini_state_t *config_state, - const gamma_method_t *gamma_methods, - const location_provider_t *location_providers) + struct options *options, struct config_ini_state *config_state, + const struct gamma_method *gamma_methods, + const struct location_provider *location_providers) { /* Read global config settings. */ - config_ini_section_t *section = config_ini_get_section( + struct config_ini_section *section = config_ini_get_section( config_state, "redshift"); if (section == NULL) return; - config_ini_setting_t *setting = section->settings; + struct config_ini_setting *setting = section->settings; while (setting != NULL) { int r = parse_config_file_option( setting->name, setting->value, options, @@ -649,7 +631,7 @@ options_parse_config_file( /* Replace unspecified options with default values. */ void -options_set_defaults(options_t *options) +options_set_defaults(struct options *options) { if (options->scheme.day.temperature < 0) { options->scheme.day.temperature = DEFAULT_DAY_TEMP; diff --git a/src/options.h b/src/options.h index 3470599..2978672 100644 --- a/src/options.h +++ b/src/options.h @@ -22,12 +22,12 @@ #include "common.h" -typedef struct { +struct options { /* Path to config file */ char *config_filepath; - transition_scheme_t scheme; - program_mode_t mode; + struct transition_scheme scheme; + enum program_mode mode; int verbose; /* Temperature to set in manual mode. */ @@ -38,26 +38,26 @@ typedef struct { int preserve_gamma; /* Selected gamma method. */ - const gamma_method_t *method; + const struct gamma_method *method; /* Arguments for gamma method. */ char *method_args; /* Selected location provider. */ - const location_provider_t *provider; + const struct location_provider *provider; /* Arguments for location provider. */ char *provider_args; -} options_t; +}; -void options_init(options_t *options); +void options_init(struct options *options); void options_parse_args( - options_t *options, int argc, char *argv[], - const gamma_method_t *gamma_methods, - const location_provider_t *location_providers); + struct options *options, int argc, char *argv[], + const struct gamma_method *gamma_methods, + const struct location_provider *location_providers); void options_parse_config_file( - options_t *options, config_ini_state_t *config_state, - const gamma_method_t *gamma_methods, - const location_provider_t *location_providers); -void options_set_defaults(options_t *options); + struct options *options, struct config_ini_state *config_state, + const struct gamma_method *gamma_methods, + const struct location_provider *location_providers); +void options_set_defaults(struct options *options); #endif /* ! REDSHIFT_OPTIONS_H */ diff --git a/src/pipeutils.c b/src/pipeutils.c index 75302cb..200fb6d 100644 --- a/src/pipeutils.c +++ b/src/pipeutils.c @@ -16,10 +16,7 @@ Copyright (c) 2017 Jon Lund Steffensen */ - -#include -#include -#include +#include "common.h" #ifndef _WIN32 diff --git a/src/redshift.c b/src/redshift.c index 60e2441..92066e1 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -16,19 +16,10 @@ Copyright (c) 2009-2017 Jon Lund Steffensen */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include +#include "common.h" +#include "config-ini.h" +#include "solar.h" +#include "options.h" /* poll.h is not available on Windows but there is no Windows location provider using polling. On Windows, we just define some stubs to make things compile. @@ -45,25 +36,6 @@ struct pollfd { int poll(struct pollfd *fds, int nfds, int timeout) { abort(); return -1; } #endif -#if defined(HAVE_SIGNAL_H) && !defined(__WIN32__) -# include -#endif - -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -# define N_(s) (s) -#else -# define _(s) s -# define N_(s) s -# define gettext(s) s -#endif - -#include "common.h" -#include "config-ini.h" -#include "solar.h" -#include "options.h" - /* pause() is not defined on windows platform but is not needed either. Use a noop macro instead. */ #ifdef __WIN32__ @@ -104,8 +76,8 @@ static const char *period_names[] = { /* Determine which period we are currently in based on time offset. */ -static period_t -get_period_from_time(const transition_scheme_t *transition, int time_offset) +static enum period +get_period_from_time(const struct transition_scheme *transition, int time_offset) { if (time_offset < transition->dawn.start || time_offset >= transition->dusk.end) { @@ -119,9 +91,9 @@ get_period_from_time(const transition_scheme_t *transition, int time_offset) } /* Determine which period we are currently in based on solar elevation. */ -static period_t +static enum period get_period_from_elevation( - const transition_scheme_t *transition, double elevation) + const struct transition_scheme *transition, double elevation) { if (elevation < transition->low) { return PERIOD_NIGHT; @@ -135,7 +107,7 @@ get_period_from_elevation( /* Determine how far through the transition we are based on time offset. */ static double get_transition_progress_from_time( - const transition_scheme_t *transition, int time_offset) + const struct transition_scheme *transition, int time_offset) { if (time_offset < transition->dawn.start || time_offset >= transition->dusk.end) { @@ -156,7 +128,7 @@ get_transition_progress_from_time( /* Determine how far through the transition we are based on elevation. */ static double get_transition_progress_from_elevation( - const transition_scheme_t *transition, double elevation) + const struct transition_scheme *transition, double elevation) { if (elevation < transition->low) { return 0.0; @@ -184,7 +156,7 @@ get_seconds_since_midnight(double timestamp) /* Print verbose description of the given period. */ static void -print_period(period_t period, double transition) +print_period(enum period period, double transition) { switch (period) { case PERIOD_NONE: @@ -202,7 +174,7 @@ print_period(period_t period, double transition) /* Print location */ static void -print_location(const location_t *location) +print_location(const struct location *location) { /* TRANSLATORS: Abbreviation for `north' */ const char *north = _("N"); @@ -224,10 +196,10 @@ print_location(const location_t *location) /* Interpolate color setting structs given alpha. */ static void interpolate_color_settings( - const color_setting_t *first, - const color_setting_t *second, + const struct color_setting *first, + const struct color_setting *second, double alpha, - color_setting_t *result) + struct color_setting *result) { alpha = CLAMP(0.0, alpha, 1.0); @@ -244,12 +216,12 @@ interpolate_color_settings( /* Interpolate color setting structs transition scheme. */ static void interpolate_transition_scheme( - const transition_scheme_t *transition, + const struct transition_scheme *transition, double alpha, - color_setting_t *result) + struct color_setting *result) { - const color_setting_t *day = &transition->day; - const color_setting_t *night = &transition->night; + const struct color_setting *day = &transition->day; + const struct color_setting *night = &transition->night; alpha = CLAMP(0.0, alpha, 1.0); interpolate_color_settings(night, day, alpha, result); @@ -259,8 +231,8 @@ interpolate_transition_scheme( Used to determine if a fade should be applied in continual mode. */ static int color_setting_diff_is_major( - const color_setting_t *first, - const color_setting_t *second) + const struct color_setting *first, + const struct color_setting *second) { return (abs(first->temperature - second->temperature) > 25 || fabsf(first->brightness - second->brightness) > 0.1 || @@ -271,7 +243,7 @@ color_setting_diff_is_major( /* Reset color setting to default values. */ static void -color_setting_reset(color_setting_t *color) +color_setting_reset(struct color_setting *color) { color->temperature = NEUTRAL_TEMP; color->gamma[0] = 1.0; @@ -282,8 +254,8 @@ color_setting_reset(color_setting_t *color) static int -provider_try_start(const location_provider_t *provider, - location_state_t **state, config_ini_state_t *config, +provider_try_start(const struct location_provider *provider, + LOCATION_STATE **state, struct config_ini_state *config, char *args) { int r; @@ -296,10 +268,10 @@ provider_try_start(const location_provider_t *provider, } /* Set provider options from config file. */ - config_ini_section_t *section = + struct config_ini_section *section = config_ini_get_section(config, provider->name); if (section != NULL) { - config_ini_setting_t *setting = section->settings; + struct config_ini_setting *setting = section->settings; while (setting != NULL) { r = provider->set_option(*state, setting->name, setting->value); @@ -374,8 +346,8 @@ provider_try_start(const location_provider_t *provider, } static int -method_try_start(const gamma_method_t *method, gamma_state_t **state, - program_mode_t mode, config_ini_state_t *config, char *args) +method_try_start(const struct gamma_method *method, GAMMA_STATE **state, + enum program_mode mode, struct config_ini_state *config, char *args) { int r; @@ -387,10 +359,10 @@ method_try_start(const gamma_method_t *method, gamma_state_t **state, } /* Set method options from config file. */ - config_ini_section_t *section = + struct config_ini_section *section = config_ini_get_section(config, method->name); if (section != NULL) { - config_ini_setting_t *setting = section->settings; + struct config_ini_setting *setting = section->settings; while (setting != NULL) { r = method->set_option( *state, setting->name, setting->value); @@ -468,7 +440,7 @@ gamma_is_valid(const float gamma[3]) Prints error message on stderr and returns 0 if invalid, otherwise returns 1. */ static int -location_is_valid(const location_t *location) +location_is_valid(const struct location *location) { /* Latitude */ if (location->lat < MIN_LAT || location->lat > MAX_LAT) { @@ -497,8 +469,8 @@ location_is_valid(const location_t *location) 0 if timeout was reached, 1 if location became available. */ static int provider_get_location( - const location_provider_t *provider, location_state_t *state, - int timeout, location_t *loc) + const struct location_provider *provider, LOCATION_STATE *state, + int timeout, struct location *loc) { int available = 0; struct pollfd pollfds[1]; @@ -566,11 +538,11 @@ ease_fade(double t) current time and continuously updates the screen to the appropriate color temperature. */ static int -run_continual_mode(const location_provider_t *provider, - location_state_t *location_state, - const transition_scheme_t *scheme, - const gamma_method_t *method, - gamma_state_t *method_state, +run_continual_mode(const struct location_provider *provider, + LOCATION_STATE *location_state, + const struct transition_scheme *scheme, + const struct gamma_method *method, + GAMMA_STATE *method_state, int use_fade, int preserve_gamma, int verbose) { int r; @@ -578,7 +550,7 @@ run_continual_mode(const location_provider_t *provider, /* Short fade parameters */ int fade_length = 0; int fade_time = 0; - color_setting_t fade_start_interp; + struct color_setting fade_start_interp; r = signals_install_handlers(); if (r < 0) { @@ -587,17 +559,17 @@ run_continual_mode(const location_provider_t *provider, /* Save previous parameters so we can avoid printing status updates if the values did not change. */ - period_t prev_period = PERIOD_NONE; + enum period prev_period = PERIOD_NONE; /* Previous target color setting and current actual color setting. Actual color setting takes into account the current color fade. */ - color_setting_t prev_target_interp; + struct color_setting prev_target_interp; color_setting_reset(&prev_target_interp); - color_setting_t interp; + struct color_setting interp; color_setting_reset(&interp); - location_t loc = { NAN, NAN }; + struct location loc = { NAN, NAN }; int need_location = !scheme->use_time; if (need_location) { fputs(_("Waiting for initial location" @@ -665,7 +637,7 @@ run_continual_mode(const location_provider_t *provider, return -1; } - period_t period; + enum period period; double transition_prog; if (scheme->use_time) { int time_offset = get_seconds_since_midnight(now); @@ -686,7 +658,7 @@ run_continual_mode(const location_provider_t *provider, /* Use transition progress to get target color temperature. */ - color_setting_t target_interp; + struct color_setting target_interp; interpolate_transition_scheme( scheme, transition_prog, &target_interp); @@ -807,7 +779,7 @@ run_continual_mode(const location_provider_t *provider, /* Get new location and availability information. */ - location_t new_loc; + struct location new_loc; int new_available; r = provider->handle( location_state, &new_loc, @@ -869,7 +841,7 @@ main(int argc, char *argv[]) #endif /* List of gamma methods. */ - const gamma_method_t gamma_methods[] = { + const struct gamma_method gamma_methods[] = { #ifdef ENABLE_COOPGAMMA coopgamma_gamma_method, #endif @@ -893,7 +865,7 @@ main(int argc, char *argv[]) }; /* List of location providers. */ - const location_provider_t location_providers[] = { + const struct location_provider location_providers[] = { #ifdef ENABLE_GEOCLUE2 geoclue2_location_provider, #endif @@ -910,13 +882,13 @@ main(int argc, char *argv[]) setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stderr, NULL, _IOLBF, 0); - options_t options; + struct options options; options_init(&options); options_parse_args( &options, argc, argv, gamma_methods, location_providers); /* Load settings from config file. */ - config_ini_state_t config_state; + struct config_ini_state config_state; r = config_ini_init(&config_state, options.config_filepath); if (r < 0) { fputs("Unable to load config file.\n", stderr); @@ -954,7 +926,7 @@ main(int argc, char *argv[]) /* Initialize location provider if needed. If provider is NULL try all providers until one that works is found. */ - location_state_t *location_state; + LOCATION_STATE *location_state; /* Location is not needed for reset mode and manual mode. */ int need_location = @@ -972,7 +944,7 @@ main(int argc, char *argv[]) /* Try all providers, use the first that works. */ for (int i = 0; location_providers[i].name != NULL; i++) { - const location_provider_t *p = + const struct location_provider *p = &location_providers[i]; fprintf(stderr, _("Trying location provider `%s'...\n"), @@ -1085,11 +1057,11 @@ main(int argc, char *argv[]) options.scheme.night.gamma[2]); } - transition_scheme_t *scheme = &options.scheme; + struct transition_scheme *scheme = &options.scheme; /* Initialize gamma adjustment method. If method is NULL try all methods until one that works is found. */ - gamma_state_t *method_state; + GAMMA_STATE *method_state; /* Gamma adjustment not needed for print mode */ if (options.mode != PROGRAM_MODE_PRINT) { @@ -1102,7 +1074,7 @@ main(int argc, char *argv[]) } else { /* Try all methods, use the first that works. */ for (int i = 0; gamma_methods[i].name != NULL; i++) { - const gamma_method_t *m = &gamma_methods[i]; + const struct gamma_method *m = &gamma_methods[i]; if (!m->autostart) continue; r = method_try_start( @@ -1132,7 +1104,7 @@ main(int argc, char *argv[]) case PROGRAM_MODE_ONE_SHOT: case PROGRAM_MODE_PRINT: { - location_t loc = { NAN, NAN }; + struct location loc = { NAN, NAN }; if (need_location) { fputs(_("Waiting for current location" " to become available...\n"), stderr); @@ -1161,7 +1133,7 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } - period_t period; + enum period period; double transition_prog; if (options.scheme.use_time) { int time_offset = get_seconds_since_midnight(now); @@ -1185,7 +1157,7 @@ main(int argc, char *argv[]) } /* Use transition progress to set color temperature */ - color_setting_t interp; + struct color_setting interp; interpolate_transition_scheme( scheme, transition_prog, &interp); @@ -1227,7 +1199,7 @@ main(int argc, char *argv[]) } /* Adjust temperature */ - color_setting_t manual = scheme->day; + struct color_setting manual = scheme->day; manual.temperature = options.temp_set; r = options.method->set_temperature( method_state, &manual, options.preserve_gamma); @@ -1249,7 +1221,7 @@ main(int argc, char *argv[]) case PROGRAM_MODE_RESET: { /* Reset screen */ - color_setting_t reset; + struct color_setting reset; color_setting_reset(&reset); r = options.method->set_temperature(method_state, &reset, 0); diff --git a/src/signals.c b/src/signals.c index 262e8f5..8cdb9e7 100644 --- a/src/signals.c +++ b/src/signals.c @@ -15,9 +15,8 @@ along with Redshift. If not, see . Copyright (c) 2009-2015 Jon Lund Steffensen - Copyright (c) 2015 Mattias Andrée + Copyright (c) 2015 Mattias Andrée */ - #include "common.h" diff --git a/src/solar.c b/src/solar.c index 9b2b59d..990929d 100644 --- a/src/solar.c +++ b/src/solar.c @@ -23,10 +23,8 @@ It is based on equations from "Astronomical Algorithms" by Jean Meeus. */ -#include - +#include "common.h" #include "solar.h" -#include "time.h" #define RAD(x) ((x)*(M_PI/180)) #define DEG(x) ((x)*(180/M_PI)) diff --git a/src/solar.h b/src/solar.h index 389484e..56f7041 100644 --- a/src/solar.h +++ b/src/solar.h @@ -28,7 +28,7 @@ #define SOLAR_CIVIL_TWILIGHT_ELEV -6.0 #define SOLAR_DAYTIME_ELEV (0.0 - SOLAR_ATM_REFRAC) -typedef enum { +enum solar_time { SOLAR_TIME_NOON = 0, SOLAR_TIME_MIDNIGHT, SOLAR_TIME_ASTRO_DAWN, @@ -40,7 +40,7 @@ typedef enum { SOLAR_TIME_NAUT_DUSK, SOLAR_TIME_ASTRO_DUSK, SOLAR_TIME_MAX -} solar_time_t; +}; double solar_elevation(double date, double lat, double lon); diff --git a/src/systemtime.c b/src/systemtime.c index f8b4794..c440c36 100644 --- a/src/systemtime.c +++ b/src/systemtime.c @@ -16,21 +16,6 @@ Copyright (c) 2010-2014 Jon Lund Steffensen */ - -#include -#include - -#ifndef _WIN32 -# if _POSIX_TIMERS > 0 -# include -# else -# include -# include -# endif -#else -# include -#endif - #include "common.h" @@ -47,7 +32,7 @@ systemtime_get_time(double *t) /* FILETIME is tenths of microseconds since 1601-01-01 UTC */ *t = (i.QuadPart / 10000000.0) - 11644473600.0; -#elif _POSIX_TIMERS > 0 /* POSIX timers */ +#elif defined(_POSIX_TIMERS) /* POSIX timers */ struct timespec now; int r = clock_gettime(CLOCK_REALTIME, &now); if (r < 0) { -- cgit v1.2.3-70-g09d2