diff options
author | Mattias Andrée <m@maandree.se> | 2025-03-21 16:50:15 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2025-03-21 16:50:15 +0100 |
commit | 96a6575e23b5baebcdd38269b80f47cc02a2627e (patch) | |
tree | 0561580306c882e0e7a4f76c542130bb7ee44537 /src/common.h | |
parent | Refactor (diff) | |
download | redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.gz redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.bz2 redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.xz |
Refactor
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'src/common.h')
-rw-r--r-- | src/common.h | 123 |
1 files changed, 95 insertions, 28 deletions
diff --git a/src/common.h b/src/common.h index e3cc37b..d9a7c3a 100644 --- a/src/common.h +++ b/src/common.h @@ -1,4 +1,5 @@ -/* redshift-ng - Automatically adjust display colour temperature according the Sun +/*- + * 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> @@ -51,7 +52,9 @@ #ifdef WINDOWS # include <windows.h> # define localtime_r(T, TM) localtime_s((TM), (T)) +# define pause() millisleep(100U) #else +# include <poll.h> # include <pwd.h> # include <time.h> #endif @@ -84,8 +87,13 @@ #if defined(__clang__) # pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* broken in clang 19.1.7 */ +# pragma clang diagnostic ignored "-Wdisabled-macro-expansion" /* warns about system headers (also a stupid warning) */ +# pragma clang diagnostic ignored "-Wassign-enum" /* warns about bit field enums */ +# pragma clang diagnostic ignored "-Wpadded" /* only relevant for library headers */ +# pragma clang diagnostic ignored "-Wcomma" /* comma is useful in loop conditions */ #elif defined(__GNUC__) -# pragma GCC diagnostic ignored "-Wunsuffixed-float-constants" +# pragma GCC diagnostic ignored "-Wunsuffixed-float-constants" /* stupid warning */ +# pragma GCC diagnostic ignored "-Wpadded" /* only relevant for library headers */ #endif @@ -126,6 +134,11 @@ */ #define BETWEEN(LO, X, UP) ((LO) < (X) && (X) < (UP)) +/** + * Quiet not-a-number `double` + */ +#define FNAN ((double)NAN) /* because clang warns when implicitly promoted to double */ + /** * Symbol used to delimit paths in environment @@ -598,8 +611,8 @@ struct settings { struct setting_f brightness; struct setting_f3 gamma; } day, night; - struct setting_i preserve_gamma; /* Whether to preserve gamma ramps if supported by gamma method. */ - struct setting_i use_fade; /* Whether to fade between large skips in colour temperature. */ + struct setting_i preserve_gamma; + struct setting_i use_fade; /* Whether to fade between large skips in colour temperature */ struct setting_f elevation_high; /* TODO no cmdline option */ struct setting_f elevation_low; /* TODO no cmdline option */ @@ -608,14 +621,14 @@ struct settings { struct setting_time end; } dawn, dusk; /* TODO no cmdline option */ - /* Selected gamma method. */ + /* Selected gamma method */ const struct gamma_method *method; - /* Arguments for gamma method. */ + /* Arguments for gamma method */ char *method_args; - /* Selected location provider. */ + /* Selected location provider */ const struct location_provider *provider; - /* Arguments for location provider. */ + /* Arguments for location provider */ char *provider_args; }; @@ -636,6 +649,12 @@ struct gamma_method { int autostart; /** + * 1 if the method automatically resets the adjustments when disconnected, + * 0 otherwise + */ + int autoreset; + + /** * Create an initialised state object * * @param state_out Output parameter for the state object @@ -703,13 +722,15 @@ struct gamma_method { * * @param NAME:const char * Value for `.name` * @param AUTOSTART:int Value for `.autostart` + * @param AUTORESET:int Value for `.autoreset` * @param PREFIX:identifier The text, sans terminal underscore (_), prefixed to the * names of each function implementing the adjustment method */ -#define GAMMA_METHOD_INIT(NAME, AUTOSTART, PREFIX)\ +#define GAMMA_METHOD_INIT(NAME, AUTOSTART, AUTORESET, PREFIX)\ {\ .name = (NAME),\ .autostart = (AUTOSTART),\ + .autoreset = (AUTORESET),\ .create = &PREFIX##_create,\ .set_option = &PREFIX##_set_option,\ .print_help = &PREFIX##_print_help,\ @@ -857,14 +878,26 @@ extern struct colour_setting night_settings; extern union scheme scheme; /** - * Whether the application is in verbose mode + * The mode the application is running in */ -extern int verbose; +extern enum program_mode mode; /** - * The mode the application is running in + * Whether initially applied adjustments (assumed + * to be colour calibration) shall remain applied */ -extern enum program_mode mode; +extern int preserve_gamma; + +/** + * Whether smooth transitions shall be applied when + * a large change in colour settings occurs + */ +extern int use_fade; + +/** + * Whether the application is in verbose mode + */ +extern int verbose; /* colour.c */ @@ -963,13 +996,44 @@ void load_settings(struct settings *settings, int argc, char *argv[]); /* gamma.c */ +/** + * Get and configure adjustment method + * + * @param settings The loaded application settings, will be updated + * to point `settings->method` to the adjustment method + * @param method_state_out Output parameter for the state of the adjustment method + * + * The function will print an error message and exit the + * process if no adjustment method is available + */ void acquire_adjustment_method(struct settings *settings, GAMMA_STATE **method_state_out); /* location.c */ -int get_location(const struct location_provider *provider, LOCATION_STATE *state, int timeout, struct location *loc); +/** + * Get the current location from the location provider + * + * @param provider The location provider functions + * @param state The location provider state + * @param timeout The number of milliseconds to wait, -1 for indefinitely + * @param location_out Output parameter for the location, in GPS coordinates + * @return 1 if `*location_out` was updated, + * 0 if the timeout was reached, + * -1 on error + */ +int get_location(const struct location_provider *provider, LOCATION_STATE *state, int timeout, struct location *location_out); +/** + * Get and configure location provider + * + * @param settings The loaded application settings, will be updated + * to point `settings->provider` to the location provider + * @param location_state_out Output parameter for the state of the location provider + * + * The function will print an error message and exit the + * process if no location provider is available + */ void acquire_location_provider(struct settings *settings, LOCATION_STATE **location_state_out); /** @@ -1064,55 +1128,58 @@ DIR *try_path_opendir(const struct env_path *path_spec, const char **path_out, c #ifndef WINDOWS /** - * Create a pipe(7) where both ends have `O_CLOEXEC` and, - * if available for pipes, `O_DIRECT`, applied, the read-end - * will also have `O_NONBLOCK` applied + * Create a pipe(7) where both ends have `O_CLOEXEC`, + * the read-end will also have `O_NONBLOCK` applied * * @param pipefds Output parameter for the pipe's file descriptors: * 0) reading file descriptor, and * 1) writing file descriptor - * @return 0 on success, -1 on failure */ -int pipe_rdnonblock(int pipefds[2]); +void pipe_rdnonblock(int pipefds[2]); #endif extern const struct gamma_method dummy_gamma_method; - #ifdef ENABLE_COOPGAMMA extern const struct gamma_method coopgamma_gamma_method; #endif - #ifdef ENABLE_RANDR extern const struct gamma_method randr_gamma_method; #endif - #ifdef ENABLE_VIDMODE extern const struct gamma_method vidmode_gamma_method; #endif - #ifdef ENABLE_DRM extern const struct gamma_method drm_gamma_method; #endif - #ifdef ENABLE_QUARTZ extern const struct gamma_method quartz_gamma_method; #endif - #ifdef ENABLE_W32GDI extern const struct gamma_method w32gdi_gamma_method; #endif - extern const struct location_provider manual_location_provider; - #ifdef ENABLE_GEOCLUE2 extern const struct location_provider geoclue2_location_provider; #endif - #ifdef ENABLE_CORELOCATION extern const struct location_provider corelocation_location_provider; #endif +#if defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wfloat-equal" +#endif +static inline int +exact_eq(double a, double b) +{ + return a == b; +} +#if defined(__GNUC__) +# pragma GCC diagnostic pop +#endif + + #endif |