diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2017-10-13 18:23:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-13 18:23:24 -0700 |
commit | d6c6aa64d7185812e8f089a84ab166f080c6aa31 (patch) | |
tree | 96ea9fa167c30a348466b9660be7b89e34d9177a /src/gamma-drm.c | |
parent | Merge pull request #536 from jonls/gtk-help-args (diff) | |
parent | Add function for resetting color_setting_t (diff) | |
download | redshift-ng-d6c6aa64d7185812e8f089a84ab166f080c6aa31.tar.gz redshift-ng-d6c6aa64d7185812e8f089a84ab166f080c6aa31.tar.bz2 redshift-ng-d6c6aa64d7185812e8f089a84ab166f080c6aa31.tar.xz |
Merge pull request #535 from jonls/cleanup
Cleanup redshift.c + modules + options
Diffstat (limited to 'src/gamma-drm.c')
-rw-r--r-- | src/gamma-drm.c | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/src/gamma-drm.c b/src/gamma-drm.c index c2ac4bd..67f819e 100644 --- a/src/gamma-drm.c +++ b/src/gamma-drm.c @@ -15,6 +15,7 @@ along with Redshift. If not, see <http://www.gnu.org/licenses/>. Copyright (c) 2014 Mattias Andrée <maandree@member.fsf.org> + Copyright (c) 2017 Jon Lund Steffensen <jonlst@gmail.com> */ #include <stdio.h> @@ -37,24 +38,49 @@ #define O_CLOEXEC 02000000 #endif +#include <xf86drm.h> +#include <xf86drmMode.h> + #include "gamma-drm.h" #include "colorramp.h" -int -drm_init(drm_state_t *state) +typedef struct { + 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; + +typedef struct { + int card_num; + int crtc_num; + int fd; + drmModeRes* res; + drm_crtc_state_t* crtcs; +} drm_state_t; + + +static int +drm_init(drm_state_t **state) { /* Initialize state. */ - state->card_num = 0; - state->crtc_num = -1; - state->fd = -1; - state->res = NULL; - state->crtcs = NULL; + *state = malloc(sizeof(drm_state_t)); + if (*state == NULL) return -1; + + drm_state_t *s = *state; + s->card_num = 0; + s->crtc_num = -1; + s->fd = -1; + s->res = NULL; + s->crtcs = NULL; return 0; } -int +static int drm_start(drm_state_t *state) { /* Acquire access to a graphics card. */ @@ -172,7 +198,7 @@ drm_start(drm_state_t *state) return 0; } -void +static void drm_restore(drm_state_t *state) { drm_crtc_state_t *crtcs = state->crtcs; @@ -185,7 +211,7 @@ drm_restore(drm_state_t *state) } } -void +static void drm_free(drm_state_t *state) { if (state->crtcs != NULL) { @@ -206,9 +232,11 @@ drm_free(drm_state_t *state) close(state->fd); state->fd = -1; } + + free(state); } -void +static void drm_print_help(FILE *f) { fputs(_("Adjust gamma ramps with Direct Rendering Manager.\n"), f); @@ -221,7 +249,7 @@ drm_print_help(FILE *f) fputs("\n", f); } -int +static int drm_set_option(drm_state_t *state, const char *key, const char *value) { if (strcasecmp(key, "card") == 0) { @@ -240,7 +268,7 @@ drm_set_option(drm_state_t *state, const char *key, const char *value) return 0; } -int +static int drm_set_temperature(drm_state_t *state, const color_setting_t *setting) { drm_crtc_state_t *crtcs = state->crtcs; @@ -288,3 +316,15 @@ drm_set_temperature(drm_state_t *state, const color_setting_t *setting) return 0; } + + +const gamma_method_t 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 +}; |