diff options
Diffstat (limited to 'src/gamma-coopgamma.c')
-rw-r--r-- | src/gamma-coopgamma.c | 72 |
1 files changed, 58 insertions, 14 deletions
diff --git a/src/gamma-coopgamma.c b/src/gamma-coopgamma.c index e3fb8e3..41a9d2b 100644 --- a/src/gamma-coopgamma.c +++ b/src/gamma-coopgamma.c @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2016 Mattias Andrée <maandree@member.fsf.org> + Copyright (c) 2016, 2025 Mattias Andrée <m@maandree.se> */ #ifdef HAVE_CONFIG_H @@ -41,6 +41,32 @@ #include "colorramp.h" +typedef struct { + char *edid; + size_t index; +} coopgamma_output_id_t; + +typedef struct { + libcoopgamma_filter_t filter; + libcoopgamma_ramps_t plain_ramps; + size_t rampsize; +} coopgamma_crtc_state_t; + +typedef struct { + libcoopgamma_context_t ctx; + coopgamma_crtc_state_t *crtcs; + size_t n_crtcs; + char **methods; + char *method; + char *site; + int64_t priority; + int list_outputs; + coopgamma_output_id_t *outputs; + size_t n_outputs; + size_t a_outputs; +} coopgamma_state_t; + + struct signal_blockage { }; @@ -65,6 +91,7 @@ update(coopgamma_state_t *state) { for (size_t i = 0; i < state->n_crtcs; i++) libcoopgamma_set_gamma_sync(&state->crtcs[i].filter, &state->ctx); + return 0; } @@ -90,12 +117,17 @@ print_error(coopgamma_state_t *state) } -int -coopgamma_init(coopgamma_state_t *state) +static int +coopgamma_init(coopgamma_state_t **state) { + *state = malloc(sizeof(coopgamma_state_t)); + if (*state == NULL) return -1; + + coopgamma_state_t *s = *state; + struct signal_blockage signal_blockage; - memset(state, 0, sizeof(*state)); - if (libcoopgamma_context_initialise(&state->ctx)) { + memset(s, 0, sizeof(*s)); + if (libcoopgamma_context_initialise(&s->ctx)) { perror("libcoopgamma_context_initialise"); return -1; } @@ -103,8 +135,8 @@ coopgamma_init(coopgamma_state_t *state) /* This is done this early to check if coopgamma is available */ if (unblocked_signal(SIGCHLD, &signal_blockage) < 0) return -1; - state->methods = libcoopgamma_get_methods(); - if (state->methods == NULL) { + s->methods = libcoopgamma_get_methods(); + if (s->methods == NULL) { perror("libcoopgamma_get_methods"); if (restore_signal_blockage(SIGCHLD, &signal_blockage) < 0) exit(EXIT_FAILURE); @@ -113,12 +145,12 @@ coopgamma_init(coopgamma_state_t *state) if (restore_signal_blockage(SIGCHLD, &signal_blockage) < 0) return -1; - state->priority = 0x0800000000000000LL; + s->priority = 0x0800000000000000LL; return 0; } -int +static int coopgamma_start(coopgamma_state_t *state, program_mode_t mode) { struct signal_blockage signal_blockage; @@ -333,7 +365,7 @@ coopgamma_start(coopgamma_state_t *state, program_mode_t mode) return 0; } -void +static void coopgamma_free(coopgamma_state_t *state) { free(state->methods); @@ -360,7 +392,7 @@ coopgamma_free(coopgamma_state_t *state) state->outputs = NULL; } -void +static void coopgamma_print_help(FILE *f) { fputs(_("Adjust gamma ramps with coopgamma.\n"), f); @@ -380,7 +412,7 @@ coopgamma_print_help(FILE *f) fputs("\n", f); } -int +static int coopgamma_set_option(coopgamma_state_t *state, const char *key, const char *value) { size_t i; @@ -471,7 +503,7 @@ coopgamma_set_option(coopgamma_state_t *state, const char *key, const char *valu return 0; } -void +static void coopgamma_restore(coopgamma_state_t *state) { size_t i; @@ -482,7 +514,7 @@ coopgamma_restore(coopgamma_state_t *state) state->crtcs[i].filter.lifespan = LIBCOOPGAMMA_UNTIL_DEATH; } -int +static int coopgamma_set_temperature(coopgamma_state_t *state, const color_setting_t *setting) { libcoopgamma_filter_t *filter; @@ -525,3 +557,15 @@ coopgamma_set_temperature(coopgamma_state_t *state, const color_setting_t *setti return update(state); } + + +const gamma_method_t 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 +}; |