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-randr.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-randr.c')
-rw-r--r-- | src/gamma-randr.c | 79 |
1 files changed, 59 insertions, 20 deletions
diff --git a/src/gamma-randr.c b/src/gamma-randr.c index 6e0fd00..e35315b 100644 --- a/src/gamma-randr.c +++ b/src/gamma-randr.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) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2010-2017 Jon Lund Steffensen <jonlst@gmail.com> */ #include <stdio.h> @@ -42,30 +42,53 @@ #define RANDR_VERSION_MINOR 3 -int -randr_init(randr_state_t *state) +typedef struct { + xcb_randr_crtc_t crtc; + unsigned int ramp_size; + uint16_t *saved_ramps; +} randr_crtc_state_t; + +typedef struct { + xcb_connection_t *conn; + xcb_screen_t *screen; + int preferred_screen; + int preserve; + int screen_num; + int crtc_num_count; + int* crtc_num; + unsigned int crtc_count; + randr_crtc_state_t *crtcs; +} randr_state_t; + + +static int +randr_init(randr_state_t **state) { /* Initialize state. */ - state->screen_num = -1; - state->crtc_num = NULL; + *state = malloc(sizeof(randr_state_t)); + if (*state == NULL) return -1; + + randr_state_t *s = *state; + s->screen_num = -1; + s->crtc_num = NULL; - state->crtc_num_count = 0; - state->crtc_count = 0; - state->crtcs = NULL; + s->crtc_num_count = 0; + s->crtc_count = 0; + s->crtcs = NULL; - state->preserve = 1; + s->preserve = 1; xcb_generic_error_t *error; /* Open X server connection */ - state->conn = xcb_connect(NULL, &state->preferred_screen); + s->conn = xcb_connect(NULL, &s->preferred_screen); /* Query RandR version */ xcb_randr_query_version_cookie_t ver_cookie = - xcb_randr_query_version(state->conn, RANDR_VERSION_MAJOR, + xcb_randr_query_version(s->conn, RANDR_VERSION_MAJOR, RANDR_VERSION_MINOR); xcb_randr_query_version_reply_t *ver_reply = - xcb_randr_query_version_reply(state->conn, ver_cookie, &error); + xcb_randr_query_version_reply(s->conn, ver_cookie, &error); /* TODO What does it mean when both error and ver_reply is NULL? Apparently, we have to check both to avoid seg faults. */ @@ -73,7 +96,8 @@ randr_init(randr_state_t *state) int ec = (error != 0) ? error->error_code : -1; fprintf(stderr, _("`%s' returned error %d\n"), "RANDR Query Version", ec); - xcb_disconnect(state->conn); + xcb_disconnect(s->conn); + free(s); return -1; } @@ -82,7 +106,8 @@ randr_init(randr_state_t *state) fprintf(stderr, _("Unsupported RANDR version (%u.%u)\n"), ver_reply->major_version, ver_reply->minor_version); free(ver_reply); - xcb_disconnect(state->conn); + xcb_disconnect(s->conn); + free(s); return -1; } @@ -91,7 +116,7 @@ randr_init(randr_state_t *state) return 0; } -int +static int randr_start(randr_state_t *state) { xcb_generic_error_t *error; @@ -228,7 +253,7 @@ randr_start(randr_state_t *state) return 0; } -void +static void randr_restore(randr_state_t *state) { xcb_generic_error_t *error; @@ -257,7 +282,7 @@ randr_restore(randr_state_t *state) } } -void +static void randr_free(randr_state_t *state) { /* Free CRTC state */ @@ -269,9 +294,11 @@ randr_free(randr_state_t *state) /* Close connection */ xcb_disconnect(state->conn); + + free(state); } -void +static void randr_print_help(FILE *f) { fputs(_("Adjust gamma ramps with the X RANDR extension.\n"), f); @@ -287,7 +314,7 @@ randr_print_help(FILE *f) fputs("\n", f); } -int +static int randr_set_option(randr_state_t *state, const char *key, const char *value) { if (strcasecmp(key, "screen") == 0) { @@ -416,7 +443,7 @@ randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, return 0; } -int +static int randr_set_temperature(randr_state_t *state, const color_setting_t *setting) { @@ -440,3 +467,15 @@ randr_set_temperature(randr_state_t *state, return 0; } + + +const gamma_method_t 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 +}; |