1 /* redshift.h -- Main program header
2    This file is part of Redshift.
3 
4    Redshift is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8 
9    Redshift is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with Redshift.  If not, see <http://www.gnu.org/licenses/>.
16 
17    Copyright (c) 2013-2017  Jon Lund Steffensen <jonlst@gmail.com>
18 */
19 
20 #ifndef REDSHIFT_REDSHIFT_H
21 #define REDSHIFT_REDSHIFT_H
22 
23 #include <stdio.h>
24 #include <stdlib.h>
25 
26 /* The color temperature when no adjustment is applied. */
27 #define NEUTRAL_TEMP  6500
28 
29 
30 /* Location */
31 typedef struct {
32 	float lat;
33 	float lon;
34 } location_t;
35 
36 /* Periods of day. */
37 typedef enum {
38 	PERIOD_NONE = 0,
39 	PERIOD_DAYTIME,
40 	PERIOD_NIGHT,
41 	PERIOD_TRANSITION
42 } period_t;
43 
44 /* Color setting */
45 typedef struct {
46 	int temperature;
47 	float gamma[3];
48 	float brightness;
49 } color_setting_t;
50 
51 /* Program modes. */
52 typedef enum {
53 	PROGRAM_MODE_CONTINUAL,
54 	PROGRAM_MODE_ONE_SHOT,
55 	PROGRAM_MODE_PRINT,
56 	PROGRAM_MODE_RESET,
57 	PROGRAM_MODE_MANUAL
58 } program_mode_t;
59 
60 /* Time range.
61    Fields are offsets from midnight in seconds. */
62 typedef struct {
63 	int start;
64 	int end;
65 } time_range_t;
66 
67 /* Transition scheme.
68    The solar elevations at which the transition begins/ends,
69    and the association color settings. */
70 typedef struct {
71 	double high;
72 	double low;
73 	int use_time; /* When enabled, ignore elevation and use time ranges. */
74 	time_range_t dawn;
75 	time_range_t dusk;
76 	color_setting_t day;
77 	color_setting_t night;
78 } transition_scheme_t;
79 
80 
81 /* Gamma adjustment method */
82 typedef struct gamma_state gamma_state_t;
83 
84 typedef int gamma_method_init_func(gamma_state_t **state);
85 typedef int gamma_method_start_func(gamma_state_t *state);
86 typedef void gamma_method_free_func(gamma_state_t *state);
87 typedef void gamma_method_print_help_func(FILE *f);
88 typedef int gamma_method_set_option_func(gamma_state_t *state, const char *key,
89 					 const char *value);
90 typedef void gamma_method_restore_func(gamma_state_t *state);
91 typedef int gamma_method_set_temperature_func(
92 	gamma_state_t *state, const color_setting_t *setting, int preserve);
93 
94 typedef struct {
95 	char *name;
96 
97 	/* If true, this method will be tried if none is explicitly chosen. */
98 	int autostart;
99 
100 	/* Initialize state. Options can be set between init and start. */
101 	gamma_method_init_func *init;
102 	/* Allocate storage and make connections that depend on options. */
103 	gamma_method_start_func *start;
104 	/* Free all allocated storage and close connections. */
105 	gamma_method_free_func *free;
106 
107 	/* Print help on options for this adjustment method. */
108 	gamma_method_print_help_func *print_help;
109 	/* Set an option key, value-pair */
110 	gamma_method_set_option_func *set_option;
111 
112 	/* Restore the adjustment to the state before start was called. */
113 	gamma_method_restore_func *restore;
114 	/* Set a specific color temperature. */
115 	gamma_method_set_temperature_func *set_temperature;
116 } gamma_method_t;
117 
118 
119 /* Location provider */
120 typedef struct location_state location_state_t;
121 
122 typedef int location_provider_init_func(location_state_t **state);
123 typedef int location_provider_start_func(location_state_t *state);
124 typedef void location_provider_free_func(location_state_t *state);
125 typedef void location_provider_print_help_func(FILE *f);
126 typedef int location_provider_set_option_func(
127 	location_state_t *state, const char *key, const char *value);
128 typedef int location_provider_get_fd_func(location_state_t *state);
129 typedef int location_provider_handle_func(
130 	location_state_t *state, location_t *location, int *available);
131 
132 typedef struct {
133 	char *name;
134 
135 	/* Initialize state. Options can be set between init and start. */
136 	location_provider_init_func *init;
137 	/* Allocate storage and make connections that depend on options. */
138 	location_provider_start_func *start;
139 	/* Free all allocated storage and close connections. */
140 	location_provider_free_func *free;
141 
142 	/* Print help on options for this location provider. */
143 	location_provider_print_help_func *print_help;
144 	/* Set an option key, value-pair. */
145 	location_provider_set_option_func *set_option;
146 
147 	/* Listen and handle location updates. */
148 	location_provider_get_fd_func *get_fd;
149 	location_provider_handle_func *handle;
150 } location_provider_t;
151 
152 
153 #endif /* ! REDSHIFT_REDSHIFT_H */
154